Issue
I have 2 activities. The first activity is the LogoActivity
. After 3 seconds I start the second activity that is my MainActivity
.
private void startCountDown(int duration, int interval) {
CountDownTimer mCountDownTimer = new CountDownTimer(duration, interval) {
@Override
public void onTick(long millisUntilFinished) {
// nothing
}
@Override
public void onFinish() {
startActivity(MainActivity.class);
finish();
}
};
mCountDownTimer.start();
}
startActivity(Class mClass)
is a method that I created to start any activity just by giving the class.
Now I am in the MainActivity
. If I exit by pressing home button and return back I see the MainActivity
, but if I press back button from MainActivity
and reopen the app from background the LogoActivity
show up first.
I dont want the users to see the LogoActivity
everytime they press back button(button from phone, not activity) from MainActivity
and restore it from background.
Why is the LogoActivity
shown if I called finish()
?
Solution
When you press back button, the instance of MainActivity is destroyed.
And then you come back to this task stack again, the LogoActivity is your default Activity so the system creates one instance of it for you.
You can make the MainActivity the default Activity in manifest.xml
<activity android:name=".MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
And start LogoActivity in the onCreate method of MainActivity so the user will see LogoActivity first.
After 3 seconds, finish the LogoActivity.
Answered By - Eric Liu
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.