Phonegap Android application restarting instead of resuming on coming back after home button click

1.7k views Asked by At

I have created PhoneGap 1.4/ with Android application with plugins.

My client reports that, when he leaves the app using the Home button, and then relaunches it using the app icon, the app relaunches from the start instead of resuming. However, when he press on lock or go to sleep the app resumes in the expected way.

The initialization process of the app is declared this way :

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.d("EMOFIDActivity", "onCreatee " + this.getIntent());
    super.loadUrl("file:///android_asset/www/index.html");
}
    @Override
public void onPause() {
    Log.d("EMOFIDActivity", "onPause " + this.getIntent());
    super.onPause();
}// On click of home button this method is getting called

@Override
public void onResume() {
    Log.d("EMOFIDActivity", "onResume " + this.getIntent());
    super.onResume();
} // On click of app icon application is getting relaunched without coming to this function.

I have included three android Plugins and overridden the onPause() & onResume() methods like this. Here also OnResume() method is not at all getting called.

    @Override
public void onPause(boolean multitasking) {
    Log.d(TAG, "onPause " + ctx.getIntent());
    super.onPause(multitasking);
    stopNfc();
}

@Override
public void onResume(boolean multitasking) {
    Log.d(TAG, "onResume " + ctx.getIntent());
    super.onResume(multitasking);
    startNfc();
}

Is there a way to resolve this problem and come back to state where I Paused my application? What could be the problem in this process?

1

There are 1 answers

0
Tarun Kumar On

I had the same problem . My app was getting restarted when i click the app icon to relaunch the already running app in the background.

Basically if the

android:launchMode

is set to standard or not set ,then a new intent is created for the app and the old paused state of app is not resumed .

So the best way around i found was to apply

android:launchMode="singleTask"

in the AndroidManifest.xml -> inside .

please conside this example :

  <activity android:name="Example" android:label="@string/app_name"
                 android:theme="@android:style/Theme.Black.NoTitleBar"                android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale"
                 android:launchMode="singleTask">
              <intent-filter>
                  <action android:name="android.intent.action.MAIN" />
                  <category android:name="android.intent.category.LAUNCHER" />
              </intent-filter>
          </activity>