Tengo el siguiente codigo que funciona ok pero Studio me lo pinta como muestra la imagen, encontre varias respuestas pero sigo sin entender que tengo que hacer para que no salga mas pintado.
public class SplashActivity extends AppCompatActivity {
private ProgressBar progressBar;
static RingProgressBar ringProgressBar;
static int progress = 0;
Handler myHandler = new Handler(){
public void handleMessage (Message msg){
if(msg.what == 0){
if(progress < 100){
progress++;
ringProgressBar.setProgress(progress);
}
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
ringProgressBar = (RingProgressBar) findViewById(R.id.progress_bar_1);
new Thread(new Runnable() {
@Override
public void run() {
for(int i=0;i<100;i++){
try{
Thread.sleep(40);
myHandler.sendEmptyMessage(0);
}catch (InterruptedException e){
e.printStackTrace();
}
}
}
}).start();
}
}
Codigo Corregido y sin warning:
public class SplashActivity extends AppCompatActivity {
static RingProgressBar ringProgressBar;
static int progress = 0;
private static class MyHandler extends Handler {
public void handleMessage(Message msg) {
if (msg.what == 0) {
if (progress < 100) {
progress++;
ringProgressBar.setProgress(progress);
}
}
}
}
private final MyHandler myHandler = new MyHandler();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
ringProgressBar = findViewById(R.id.progress_bar_1);
final Intent i = new Intent(this, MainActivity.class);
ringProgressBar.setOnProgressListener(new RingProgressBar.OnProgressListener() {
@Override
public void progressToComplete() {
Toast.makeText(SplashActivity.this, "Bienvenido!", Toast.LENGTH_SHORT).show();
Thread timer = new Thread(){
public void run(){
try{
sleep(2000);
}
catch (InterruptedException e){
e.printStackTrace();
}
finally {
startActivity(i);
finish();
}
}
};
timer.start();
}
});
new Thread(new Runnable() {
@Override
public void run() {
for(int i=0;i<100;i++){
try{
Thread.sleep(40);
myHandler.sendEmptyMessage(0);
}catch (InterruptedException e){
e.printStackTrace();
}
}
}
}).start();
}
}