0

I am developing an app in which I have activity called "A" and another activity called "B". I used intent to navigate between "A" to "B", but when my app goes in background Intent still works.
What I want when app goes in pause state stop navigating from"A" to "B".How can I do that?

Here is code:

public class CSplashScreen extends AppCompatActivity {
// Splash screen timer
private static final int m_n_SplashTimeOut = 4000;
private ImageView splash_image;
private boolean isConnected;
private static CLoginSessionManagement s_oCloginSession;// refernce of loginsession management
public void onAttachedToWindow() {
    super.onAttachedToWindow();
    Window window = getWindow();
    window.setFormat(PixelFormat.RGBA_8888);
}
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash);
    if (NetworkUtil.isConnected(getApplicationContext())){

    }else {
        CSnackBar.getInstance().showSnackBarError(findViewById(R.id.mainLayout), "No internet connection available", getApplicationContext());
    }
    init();//initialize controls

}
private void init() {// initialize controls

    Animation animation = null;
    splash_image = (ImageView) findViewById(R.id.splash_image);
    animation = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.zoom_out);
    animation.setDuration(1500);
    splash_image.startAnimation(animation);
    new Handler().postDelayed(new Runnable() {
        //          This method will be executed once the timer is over
        @Override
        public void run() {
            Intent i = new Intent(CSplashScreen.this, CMainActivity.class);
            startActivity(i);
        }
    }, m_n_SplashTimeOut);// spalsh screen timing


}

}

Rajesh
  • 123
  • 1
  • 2
  • 9

2 Answers2

0
@Override
public void run() {
    if (!isFinishing()) {
        startActivity(new Intent(CSplashScreen.this, CMainActivity.class));
    }
}
Karakuri
  • 38,365
  • 12
  • 84
  • 104
  • (!isFinishing) method – Rajesh May 24 '16 at 03:29
  • @Rajesh did you try this solution ? – Linh May 24 '16 at 03:41
  • This will prevent sending the intent if the user closes your splash screen (e.g. by pressing the back button). Documentation: https://developer.android.com/reference/android/app/Activity.html#isFinishing() – Karakuri May 24 '16 at 03:43
  • it navigate when app goes in pause state – Rajesh May 24 '16 at 03:50
  • Could you explain how your answer addresses the problem(s) from the question? Code-only answers are not very useful, especially for further readers that stumble upon this post. Thanks! – Cristik May 24 '16 at 06:24
0

You can have a flag like 'isPauch'.. make it true in in onPause() and make it false in onResume(). And check if flag is false then move to other activity.

Shubham
  • 521
  • 4
  • 11