navid abutorab
navid abutorab

Reputation: 189

android- How to close application and starts from first

there is something very weird in my application , suppose I go to activity A and then I go to activity B , then I go to activity A again . in this step ,If I pass back button twice , it close the app by this code:

Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_HOME);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);

and It closes the app .

the problem is , If I press and hold home button and click on app, it opens the app but not from the activity A , it opens from activity B .

the question is ,How can I close app completely when the user press back button twice and if it opens again ,it starts from activity A not B ?

Upvotes: 1

Views: 83

Answers (2)

androidXP
androidXP

Reputation: 1719

In your Android manifest File add this which you want to lunch first when application opens

<activity android:name=".ActivityName" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

You can also add

android:parentActivityName="com.example.app_name.A" In other activities to mark this activity as parent

Upvotes: 0

moud
moud

Reputation: 749

Make sure that your ActivityA has the following tag <category android:name="android.intent.category.LAUNCHER" /> in the Manifest File

Upvotes: 1

Related Questions