2

I have a splash screen activity at the startup of app. the startup splash screen has finish(), so user will not see startup splash screen anymore when they press BACK from the last remain activity. But instead of app directly exit, I want the app show a exit splash screen which has different images than startup splash screen, after that the app will directly end.

So I want it to be like this : Splash screen 1(Beginning) -> Activity A -> Activity B -> (Press Back) -> Show Activity A -> (Press Back Again) -> Splash screen 2 (End)

How to do that?

Do I have to override back button on Activity A or there's another method to show new activity when user press back button on Activity A ?

efransiscus
  • 372
  • 2
  • 17
  • You are on track about the implementation. Just override the onBackPressed() in Activity A. But make sure that Activity A is not instantiated anywhere else. Or else your 2nd splash screen will pop up in the middle. – Shubhayu Apr 16 '12 at 10:47
  • yes, i will make sure Activity A will not be instantiated in other place, thank you for the reminder :) – efransiscus Apr 17 '12 at 00:56

5 Answers5

5

Why don't you override back button on Activity A with starting activity code for Splash 2? I think this is the only solution.

For example:

@Override
public void onBackPressed() {
   Intent setIntent = new Intent(ActivityA.this, Splash2.class);
   startActivity(setIntent);
   finish();
}
Paresh Mayani
  • 127,700
  • 71
  • 241
  • 295
1

You can just override finish() method, adding startActivity.

goodm
  • 7,275
  • 6
  • 31
  • 55
1

As simple as

  1. call your activity A from splash with startActivityForResult method without calling finish

  2. override onActivityResult of splash to show the end splash screen

Rohit Sharma
  • 13,787
  • 8
  • 57
  • 72
  • start A with unique request code so that onActivityResult can be assured that it is coming from A only. for your case if A is the only screen to start from splash this won't be needed too. but would be a good practise – Rohit Sharma Apr 16 '12 at 10:42
  • How to start A with unique request code so that onActivityResult can be assured that it is coming from A only? I understand about the over riding bit no idea yet how to use onActivityResult. *I'm still a noob, sorry* – efransiscus Apr 16 '12 at 18:00
1

Depending on when you want the user to exit. If it's only in Activity A, you can simply override onKeyDown in that one, otherwise override it in each Activity you got.

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if ((keyCode == KeyEvent.KEYCODE_BACK)) {
        startActivity(new Intent("com.android.splashscreen"));
        finish();
    }
}

Create and start your end-splashscreen.

Priebe
  • 4,942
  • 3
  • 24
  • 38
0

over ride method of Activity A onBackPressed(). Inside this you can start your splash screen 2/END activity.

PrincessLeiha
  • 3,144
  • 4
  • 32
  • 53