Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

multiple Instance running of the same app in kitkat android

Is there any way to stop app running multiple instance? I have tried single instance in manifest also but did not succeed.

I have make a demo app for fetching Facebook friends. It works good in 4.2.2 and other but in kitkat 4.4.2 after login when i fatch friends it crashes and in DDMS app shows multiple instance running of the same app.

Can anyone help me or guide what is the issue?

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>

like image 669
Amish Avatar asked Sep 17 '14 06:09

Amish


1 Answers

You should use as per official documentation mode="singleTask" or mode="singleInstance".

singleTask

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

singleInstance

Same as "singleTask", except that the system doesn't launch any other activities into the task holding the instance. The activity is always the single and only member of its task.

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

If your problem persist please post the exception stack trace.

like image 101
Proverbio Avatar answered Oct 04 '22 04:10

Proverbio