• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Doubt about Activities life cycle

Hi

I have an application that have two activities, lets name they A and B for convention.

A calls B.

In activity B, I implemented the method onSaveInstanceState to save data members on the Bundle, and in the method OnCreate I implemented to take the datas from the Bundle.

Everything is working fine, but if I kill the application or restart the fone, the application starts with activity A, how can I inform to Android that he have to call activity B or what I have to implement?

I believe that restart the fone is a way to simulate the Android procedures when he will kill my application because low memory. Am I right?

Sorry for the bad english.
 
I'm having another problem too, in the same application, I have three activities, lets name they A, B and C for convention.

A calls B with StartActivity.
When user hit the back/cancel button, I have to call Activity C, so I implemented in OnPause function to call Activity C, but I need return from activity C, so I called Activity C with startActivityForResult and implemented the method onActivityResult in Activity B to get the return.

Everything is working fine, but when activity C finishes, the application is getting back to Activity A, and I need Activity B.

I have to call Activity B explicitly again or I made something wrong?
 
Upvote 0
I believe if your activity is truly "killed" either by the phone rebooting, or the OS removing it from memory, you will lose the savedInstanceState Bundle

If you need data to persist beyond that, you shoud look at SharedPreferences or other more persistent storage.

Data Storage | Android Developers

As to your second post, in order to stop the back button from going back to "A" you will need to Override the onKeyPress event and capture it so that the OS cannot process it

see here:

is there a default back key(on device) listener in android? - Stack Overflow

hope that helps!
 
  • Like
Reactions: jonathanrz
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones