0

I'm using SlidingMenu and 3/4 navigation is done by it. And if I want to go back I have to went through all these activities which I open before. I would like to change it to such that closing any child activity (not a main activity) sends me to app main activity, and if then I press back it exit app. Simple as that.

I open new activities that way:

Intent LinieActivity = new Intent(Oznaczenia.this, Linie.class);
            startActivity(LinieActivity);

and I have tried putting in my Manifest such thing:

<activity
        android:name=".childActivity"
        android:label="some name">
        <meta-data
        android:name="android.support.PARENT_ACTIVITY"
        android:value="com.example.MainActivity" />
    </activity>
Michał Tajchert
  • 10,333
  • 4
  • 30
  • 47

2 Answers2

4

Once you are done with an activity, you can call the command finish(); to close that page. So I would call the next page I want to open using an intent, then after that call finish(); and the page will close.

ItemPage ItemPage = new ItemPage();
Intent i = new Intent(context, ItemPage.class);
startActivity(i);
finish();

When you hit the back button, none of the pages you called finish on will be there.

verybadalloc
  • 5,768
  • 2
  • 33
  • 49
Mike
  • 413
  • 2
  • 12
0

Hey here is the code for back button pressed you can mange if you want to exit you can otherwise you can go to your main activity

   @Override
    public void onBackPressed() {
    new AlertDialog.Builder(this)
    .setTitle("Exit App?")
    .setMessage("Are you sure you want to exit?")
    .setNegativeButton(android.R.string.no, null)
    .setPositiveButton(android.R.string.yes, new OnClickListener() {

        public void onClick(DialogInterface arg0, int arg1) {
            WelcomeActivity.super.onBackPressed();
        }
    }).create().show();
    }
androidgeek
  • 3,440
  • 1
  • 15
  • 27