Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How should I define launchMode in AndroidManifest.xml - Using PhoneGap & JQM

I am struggling to restrict my application to a single instance. Currently if the user presses home screen to quit the application, then does something outside and clicks on the application's icon again, it launches the App's second instance.

Here is my complete manifest file:

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.mydomain.qfa"
      android:versionCode="4"
      android:versionName="1.3">


<uses-sdk android:minSdkVersion="7"
          android:targetSdkVersion="13"
          android:maxSdkVersion="18" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />

<application 
             android:debuggable=["false"]
             android:testOnly=["false"]
             android:icon="@drawable/icon.png"
>
<activity 
            android:name="com.mydomain.qfa"
            android:launchMode=["singleTask"]
            android:alwaysRetainTaskState="true"
            android:icon="@drawable/icon.png"
>
</activity>

</application>
</manifest>

Its a single activity app (basically no activities defined). On the main JQM page i have something like these entries:

<div data-role="page" id="HomePage">

    <div data-theme="d" data-role="header" data-position="fixed" style="padding-bottom: 0px;" data-tap-toggle="false">

        <div data-role="navbar">                                      

    <div data-role="content"  class="MainContent"  style="overflow:hidden; padding-top: 0px;">

Can someone please tell me if my Manifest is correct and if I should be using

android:name="com.mydomain.qfa"

or should it something else like

android:name="com.mydomain.qfa.HomePage"?

or

android:name="com.mydomain.qfa.MainContent"?

Thanks in Advance.

like image 556
AnR Avatar asked Feb 13 '14 08:02

AnR


2 Answers

I struggled with this problem for 2 days. The fix for adding this attribute was only recently added to Cordova as of 3.5, issue CB-6048

add:

<preference name="AndroidLaunchMode" value="singleTask" />

to config.xml

Other available values:

  • "standard"
  • "singleTop"
  • "singleTask"
  • "singleInstance"
like image 63
kyler Avatar answered Nov 16 '22 01:11

kyler


Try with

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

it's what's generated by phonegap CLI and launchmode set to singleTop to have single instance.

android:name must match the name of the main java class of the activity, not the full package name. By default phonegap sets it as the app name.

like image 38
QuickFix Avatar answered Nov 16 '22 02:11

QuickFix