Multiple instances of running the same application in kitkat android

Can I stop an application running multiple instances? I also tried one instance in the manifest, but could not.

I made a demo application to retrieve Facebook friends. It works well in 4.2.2 and others, but in kitkat 4.4.2, after logging in, when I meet friends, it crashes and several instances of the same application are displayed in the DDMS application.

Can someone help me or decide what the problem is?

Here is the manifest file

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="18" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" android:name="com.example.MyApplication" > <activity android:name=".Splash" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name="com.example.ui.newHome" android:screenOrientation="portrait" /> <activity android:name="com.example.ui.FriendsList" android:screenOrientation="portrait" /> <activity android:name="com.facebook.LoginActivity" android:label="@string/app_name" android:theme="@android:style/Theme.Translucent.NoTitleBar" /> <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/app_id" /> </application> 

+6
source share
3 answers

You should use mode = "singleTask" or mode = "singleInstance" according to the white paper.

singleTask

The system creates activity at the root of the new task and redirects it to it. However, if an action instance already exists, the system redirects the intent to the existing instance by calling its onNewIntent () method, rather than creating a new one.

singleInstance

Same as singleTask, except that the system does not run any other actions on the task containing the instance. Activity is always the only and only member of its task.

http://developer.android.com/guide/topics/manifest/activity-element.html

If your problem persists, send an exception stack trace.

+1
source

Try the following in a start operation in onCreate

 if(!isTaskRoot()){ finish(); return; } 

This will prevent multiple instances of the same application from being used.

0
source

In your manifest file, enable android:launchMode="singleInstance"

0
source

Source: https://habr.com/ru/post/975392/


All Articles