multithreading - Android studio splash screen loops my activity - threading -


first of i´m new android. have found piece of code make splash on app startup. when integrated project infinitive loop on login/second activity. i´m guessing wrong threading.

import android.app.activity; import android.content.intent; import android.graphics.pixelformat; import android.os.bundle; import android.view.window; import android.view.animation.animation; import android.view.animation.animationutils; import android.widget.imageview; import android.widget.linearlayout;    public class welcomesplashlogo extends activity{  public void onattachedtowindow() {     super.onattachedtowindow();     window window = getwindow();     window.setformat(pixelformat.rgba_8888); }  thread splashtread; @override public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.welcome_splash_logo);     startanimations();   }  private void startanimations() {     animation anim = animationutils.loadanimation(this, r.anim.alpha);     anim.reset();     linearlayout l=(linearlayout) findviewbyid(r.id.lin_lay);     l.clearanimation();     l.startanimation(anim);      anim = animationutils.loadanimation(this, r.anim.translate);     anim.reset();     imageview iv = (imageview) findviewbyid(r.id.splash);     iv.clearanimation();     iv.startanimation(anim);      splashtread = new thread() {         @override         public void run() {             try {                 int waited = 0;                 // splash screen pause time                 while (waited < 3500) {                     sleep(100);                     waited += 100;                 }                 intent intent = new intent(welcomesplashlogo.this, welcomesplashlogo.class);                 intent.setflags(intent.flag_activity_no_animation);                 startactivity(intent);                 welcomesplashlogo.this.finish();             } catch (interruptedexception e) {                 // nothing             } {                 welcomesplashlogo.this.finish();                  intent intentgotohomeactivity = new intent(welcomesplashlogo.this, loginactivity.class);                 welcomesplashlogo.this.startactivity(intentgotohomeactivity);             }          }     };     splashtread.start();  } 

}

it because of below lines:

intent intent = new intent(welcomesplashlogo.this, welcomesplashlogo.class);             intent.setflags(intent.flag_activity_no_animation);             startactivity(intent);             welcomesplashlogo.this.finish(); 

you calling same activity i.e. welcomesplashlogo.class.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -