Kognos
Kognos

Reputation: 756

Android: Get initialization code to run every time user launches app

I have an app with a main activity (A) with menus, and separate activities (B, C, D) for the tasks selected from the menu. I have initialization code which is currently in onCreate(). But if the user leaves the app by pressing the home button, and then re-launches by tapping the app icon, onCreate() does not run. I cannot put the initialization code in onRestart(), as this runs when the user returns to the menu after a task run by say B. How can I get the code to run on every launch, but only on launch?

Upvotes: 0

Views: 216

Answers (1)

Logain
Logain

Reputation: 4374

First you need to understand how the android life cycle works: http://developer.android.com/training/basics/activity-lifecycle/index.html

enter image description here

Basically, you need to run your code on onResume and onStart depending on what you want to achieve


EDIT:

Since the icon launches a VIEW intent, you could check for the intent when the application is resumed or restarted.

Upvotes: 1

Related Questions