We are experiencing a weird issue. Our app is already uploaded to Google Play. When I download our app from Google Play, I found out that 2 shortcuts are created for our app. One is created during download and install of our app at Google Play. When I click to run our app in the Google Play, our splash screen activity would be launched which would create another shortcut ( our code does check if the shortcut is already created or not).
Now both shortcuts are there and are acting differently. If I launched my app from first shortcut, and entered some information in the screen and then go back to home screen. and click the same shortcut again, those entered information is still there. However if I click on another shortcut after I go to home screen, the splash screen would show again, all the entered data is gone. If I see the running app (press Home and hold), I could see only one running activity for our app.
Here is the code we create the shortcut:
public static void createShortcut(Activity activity, int iconResId,
int appNameResId) {
Intent shortcutIntent = new Intent(
"com.android.launcher.action.INSTALL_SHORTCUT");
shortcutIntent.putExtra("duplicate", false);
shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME,
activity.getString(appNameResId));
Parcelable icon = Intent.ShortcutIconResource.fromContext(
activity.getApplicationContext(), iconResId);
shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);
Intent extraIntent = new Intent(activity.getApplicationContext(),
activity.getClass());
extraIntent.setAction("android.intent.action.MAIN");
extraIntent.addCategory("android.intent.category.LAUNCHER");
shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, extraIntent);
activity.sendBroadcast(shortcutIntent);
}
here is code which we are checking if duplicate shortcut is already created, basically we are checking if a shortcut with our app name is already created which I know that it is not bulletproof since other app would use same name as our app as well such as I saw couple "Flashlight" app. Another thing is that it is obvious our app doesn't detect the shortcut created from Google Play app:
public static Boolean isShortcutInstalled(Activity activity,
int appNameResId) {
final ContentResolver cr = activity.getContentResolver();
String authorityString = null;
if (Build.VERSION.SDK_INT >= 8) {
authorityString = "com.android.launcher2.settings";
} else {
authorityString = "com.android.launcher.settings";
}
Uri contentUri = Uri.parse("content://" + authorityString
+ "/favorites?notify=true");
Cursor cursor = cr.query(contentUri, new String[] { "title",
"iconResource" }, "title=?",
new String[] { activity.getString(appNameResId) }, null);
if (cursor != null && cursor.getCount() > 0) {
return true;
}
return false;
}
by the way, here is another question on SO: Is it possible to prevent the Google Play app from creating a shortcut of my App on install?, however the answer on it doesn't really address the question fully though.
I am really confused now, could someone shed some lights here?
Update 1 (Dec 17):
here is the android manifest file ( I replaced some name to remove some sensitive information). The SplashActivity is the entry point for our app.
<?xml version="1.0" encoding="utf-8"?>
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
<uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT"/>
<uses-permission android:name="com.android.launcher.permission.READ_SETTINGS"/>
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<application
android:name=".xxApplication"
android:allowBackup="true"
android:icon="@drawable/xx_logo"
android:label="@string/app_label"
android:theme="@style/xxTheme.Holo" >
<activity
android:name="com.xx.xx.android.MainActivity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.xx.xx.android.TestActivity"
android:label="TestActivity"
android:screenOrientation="portrait" >
<!--
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
-->
</activity>
<activity
android:name="com.LS.zxing22.android.CaptureActivity"
android:configChanges="orientation|keyboardHidden"
android:screenOrientation="portrait"
android:theme="@style/xxTheme.NoTitleBar"
android:windowSoftInputMode="stateAlwaysHidden" >
</activity>
<activity
android:name=".ui.EnrollmentActivity"
android:screenOrientation="portrait"
android:theme="@style/xxTheme.NoTitleBar" >
</activity>
<activity
android:name=".ui.LoginActivity"
android:screenOrientation="portrait"
android:theme="@style/xxTheme.NoTitleBar" >
</activity>
<activity
android:name=".ui.AgreementActivity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name=".ui.UsagePolicyActivity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name=".ui.FinishActivity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name=".ui.MainActivity"
android:screenOrientation="portrait"
android:theme="@style/xxTheme.Holo.Menu" >
</activity>
<activity
android:name=".ui.AccessPasswordActivity"
android:label="@string/activity_label_access_password"
android:screenOrientation="portrait" >
</activity>
<activity
android:name=".ui.LoginCodeActivity"
android:label="@string/activity_label_login_code"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="org.wordpress.passcodelock.PasscodeUnlockActivity"
android:screenOrientation="portrait"
android:theme="@style/xxTheme.NoTitleBar" >
</activity>
<activity
android:name="org.wordpress.passcodelock.PasscodePreferencesActivity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="org.wordpress.passcodelock.PasscodeManagePasswordActivity"
android:screenOrientation="portrait"
android:theme="@style/xxTheme.NoTitleBar" >
</activity>
<activity
android:name=".ui.SplashActivity"
android:screenOrientation="portrait"
android:theme="@style/xxTheme.NoTitleBar.Splash" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ui.TutorialActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="com.xx.xx.android.ui.TutorialActivity.Action" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<service
android:name="com.xx.xx.android.services.xxService"
android:enabled="true" >
<intent-filter>
<action android:name="com.xx.xx.android.services.IxxServiceRemoteInterface" />
</intent-filter>
</service>
<service
android:name="com.xx.xx.android.services.NetworkIntentService"
android:enabled="true" >
</service>
<service
android:name="com.xx.xx.android.services.xxAppIntentService"
android:enabled="true" >
</service>
<service
android:name="com.xx.xx.android.services.DeviceAttributeUploadIntentService"
android:enabled="true" >
</service>
<service
android:name="com.xx.xx.android.services.HeartbeatIntentService"
android:enabled="true" >
</service>
<service
android:name="com.xx.xx.android.services.DeviceWipeIntentService"
android:enabled="true" >
</service>
</application>