ARK
ARK

Reputation: 57

Activity control

Suppose assume that there are 3 Activities A ,B and C. On the first launch of my application B is created through A. But on subsequent uses of the application I want the application to launch from B and go to C. How do I do that?

(for example Activity A asks for the number of buttons created and in B so many buttons are created for further activities performed by C. A should be used only on the initialisation and not on further use of app. But the state of the activity created by A in B has to remain the same)

Any references or sample code could be helpful
Thanks in advance.

Upvotes: 0

Views: 197

Answers (3)

Akash Singh
Akash Singh

Reputation: 5241

Use this code in your A, B And C Class

 public boolean onKeyDown(int keyCode, KeyEvent event)
     {
         if(keyCode == KeyEvent.KEYCODE_BACK){  
            finish();
            }
            return super.onKeyDown(keyCode, event);
     }

Upvotes: 1

Kristopher Micinski
Kristopher Micinski

Reputation: 7672

This can be accomplished a number of ways, but not too many sure fire ones: the basic approach you will use is a splash screen along with a flag variable stored somewhere. As one of your comments mentions, whenever you enter Activity A, you can always set the flag in a SharedPreferences. When you go back to this activity in the future, you can simply check whether or not the flag is set and then perhaps make a new Intent to start activity C from B. You can also do a similar thing with A, where checking the flag you choose to go to the app. One tricky situation is how to reset the flag. There are a few options, you could conservatively reset the flags in onStop(), which may or may not be a good idea, after you think about the lifecycle. You may also register a boot completed handler, and then reset the flags there, which would essentially let you restart the behavior each time the system boots.

Upvotes: 0

Kapil Kshemkalyani
Kapil Kshemkalyani

Reputation: 66

You can always start your application through activity A. In A, check if it is first time or not. If it is first time then do number of initialization operations and start B. Otherwise directly start B. You can store isFirstTime flag into preferences.

Upvotes: 1

Related Questions