3

I have created an android app with 5 activities .i.e 1.java,2.java,3.java,4.java,5.java. and Splash also there.

I have used intents to move from one activity to another. I have defined few operations on buttons i.e changing the background image of that button and assigning values to strings in that activities.

I used moveTaskToBack() method on clicking back button from all my java files.

and i have kept android:launchMode="singleInstance" in manifest file.

from 5.java I have to move to Splash page and have to restart whole app ..

when i have moved from Splash to 1.java page it is showing previously entered details ..

my problem is how to clear all the previously entered details in 1.java page,2.java page,3.java page,4,java page,5.java page.

please give answer...thank uu...

N J
  • 27,217
  • 13
  • 76
  • 96
Saranya
  • 733
  • 1
  • 6
  • 7
  • when you are using back button java 5 to 4 or Java 4 to 3 use finish(); – Android Dev Jun 29 '15 at 11:01
  • 1
    call finish(); when you call new Intent; – Chirag Savsani Jun 29 '15 at 11:02
  • For which API level? Maybe if 11+ this could help: http://stackoverflow.com/questions/6330260/finish-all-previous-activities – Thomas W. Jun 29 '15 at 11:06
  • thanking u for answering.. – Saranya Jun 29 '15 at 11:44
  • I have called finish(); from all activities..But when i pressed back button from 4.java it have show the previously entered details in 3,java like wise from 2.java,3.java also.. – Saranya Jun 29 '15 at 11:47
  • I have to clear after restarting from Splash to 1.java and so on – Saranya Jun 29 '15 at 11:48
  • For that there are 2 approach 1 is start next activity using startactivityforresult and resultcode on onActivityresult and 2 is make static flag and check that flag on each activity and then finish activity – Pavya Jun 29 '15 at 11:51
  • please tell me in detail – Saranya Jun 29 '15 at 11:55
  • I have found the answer that just creating public static Activity fa; outside onCreate and in onCreate(){fa=this;} in all activities and finishing 1.fa.finish();2.fa.finish();3.fa.finish();4.fa.finish(); in 5.java onCreate. – Saranya Jun 30 '15 at 06:17

5 Answers5

2

Just call finish() before you starting the another Activity

Amrut Gaikwad
  • 524
  • 1
  • 3
  • 19
2

Considering you are moving from java5 class to Splash Screen.

You need to clear the previously opened activities like this;

Intent intent = new Intent(Java5Class.this, SplashScreen.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
this.finish();
A.R.
  • 2,631
  • 1
  • 19
  • 22
1

try like this, it will work while pressing backbutton

   @Override
        public boolean onKeyDown(int keyCode, KeyEvent event) 
        {
            if ((keyCode == KeyEvent.KEYCODE_BACK))
            {


                Intent intent = new Intent(getApplicationContext(), previousActivvty.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                intent.putExtra("EXIT", true);
                startActivity(intent);
                finish();
            }
            return super.onKeyDown(keyCode, event);
        }
Android Dev
  • 421
  • 8
  • 26
1

Try this

 Intent intent = new Intent(getApplicationContext(), Home.class);
 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
 startActivity(intent);
 finish();

This will clear all the activities on top of home.

Kinjal
  • 1,195
  • 4
  • 13
  • 24
1

after starting new activity, finish the activity you want to destroy.

StartActivity(new Intent(this,Second.class));
finish();