Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the proper way to resume an Android Phonegap app?

I'm not sure if this is expected, if it's a bug and whether or not there's a workaround.

When a user hits the home button in our Android Phonegap app, the application minimizes properly. When the user clicks the icon to launch the app, it restarts from the beginning. This is undesirable.

After a user minimizes the app by clicking the home button, there are two ways the app will resume properly:

  1. A long press on the home button and clicking the app will resume the app in its last state.
  2. Clicking a notification in the status bar (push notification) will resume the app in its last state.

So my question is, what do we need to do to resume the app in the same way those above two items do when the user clicks on the app icon from the desktop? The app is running and healthy as item 1 listed above confirms.

Any help would be greatly appreciated. Thanks!

like image 858
Ryan Martin Avatar asked Jul 26 '12 20:07

Ryan Martin


1 Answers

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 <activity> .

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>
like image 194
Tarun Kumar Avatar answered Nov 10 '22 03:11

Tarun Kumar