I am having an architectural problem with an Android project. I have the main activity(A) where a lot of stuff is initialized then I have 1 Activity(B) that handles some broadcasts from the system, this activity needs to access the stuff initialized by the main activity. If the app is killed and the activity (B) is called the onCreate of the Activity (A) is not called so the stuff is not initialized, how can I handle this situation properly?
-
Tell me one thing. When the app is launched 1st time, Activity A should have been created, then activity B which is dependent on Activity A. Not if the app is killed and recreated, make it to go through same process. Create Activity A and then Activity B should be created.. – Sushil Feb 20 '14 at 08:03
3 Answers
That's a sign of not properly encapsulating the logic.
I don't know what your app is about, so that makes it difficult to generalize, but probably your Activity A has a lot of objects and variables related to you model, what you should do is isolate all this logic of your model in a single component, that you can initialize with a single call (or a few lines) either from activity A or B.
This logic can include opening files or sharedPreference, initializing objects, downloading data... Ideally all the logic is isolated from the user interface. The User Interface, on the other hand should be only responsible to present the data in a human readable (and hopefully enjoyable) way.

- 8,140
- 1
- 24
- 39
When first time your activity B is called, pass all initialization values to it from Activity A and save the in Activity B.
If app is killed and activity B is called, it have all the initialized values.

- 1,333
- 2
- 14
- 38
You should develop App using MVC arthitucture
Check this MVC Pattern in Android Development
This will help you batter.