0

I starting intent service in onCreate() method in subclass of Application class. But it is called when app is opened the first time. It should not calling on every time the app is opened. It does even not work when I kill the background process. And my observation its working in galaxy note but not in samsung s duos, please help me.

public class MyApp extends Application {
@Override
public void onCreate() {
Toast.makeText(this.getApplicationContext(), "APPLICATION", Toast.LENGTH_LONG).show();
context=this.getApplicationContext();
if (!ContactUtiles.isFileExit()) {

    createDatabase(Opration.NOT_FOR_DELTA);
    if (DBConstants.LOGD) {Log.d(TAG, DBConstants.DB_NOT_EXIST);}


}
super.onCreate();
}
}

1 Answers1

1

You should read this about the Android Acitvity Lifecycle: http://developer.android.com/training/basics/activity-lifecycle/index.html

In short: onCreate() will be called when the Activity has to be created.

If you launch an app, tha Activity will have to be created. If you go to background, the Activity will most probably not be destriyed until certain time passes, so when you return to the app there will be no need to create the Activity (it wasn't destroyed).

If you want your code to execute every time, you should user onResume(). onResume() is called every time before the Activity is showed.

Mikel Pascual
  • 2,202
  • 18
  • 27