Devesh Agrawal
Devesh Agrawal

Reputation: 9212

How to have an activity with single instance in android

I am using this flag in manifest.xml to have only one instance of the activity.

android:launchMode="singleInstance"

But if this activity say A launches a new activity say B and then pressing back button on B not showing activity A. It is showing activity from where we launched A.

Basically i want to create a activity if it is not in stack and if in stack bring on the top. But back button should also work properly.

What flag i should use for this.

Upvotes: 0

Views: 831

Answers (2)

Ankit Aggarwal
Ankit Aggarwal

Reputation: 5375

use android:launchMode="singleTask" instead of android:launchMode="singleInstance"

Upvotes: 1

Prathap Badavath
Prathap Badavath

Reputation: 1671

following code activityA(parent activity),then A launch activity b. Declare these lines in manifest.xml file. When click back button it goes to previous activity(i.e A(parent)).

<activity
        android:name=".ActivityB"
        android:label="@string/app_name"
        android:parentActivityName=".ActivityA"
        android:windowSoftInputMode="adjustPan" >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.prathap.ActivityA" />
    </activity>

Upvotes: 0

Related Questions