简体   繁体   中英

Restored the last activity and finish the previous activity

how would i restore my last activity even when the user close the application and finish the previous one. What i mean is that, when the user reopen the application that has been close he will still see the last activity and when he press the back button of the emulator he would never see the the previous activity it will direct to the home page of the emulator (it is something like the previous activity will finish so it will never come back to the previous activity). please i need a help, please explain it very clear, im sorry i am new in android. one more request if it can, could you please explain step by step.

This is my 1st activity

public class MainActivity extends Activity {

public EditText txt_Emp, txt_Email, txt_Security;
public ImageButton btn_Submit, btn_Generate, btn_Resend;
final Context context = this;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


     txt_Emp = (EditText) findViewById(R.id.txt_emp);
     txt_Email = (EditText) findViewById(R.id.txt_email);
     txt_Security = (EditText) findViewById(R.id.txt_code);
     btn_Submit = (ImageButton) findViewById(R.id.btn_submit);
     btn_Generate = (ImageButton) findViewById(R.id.btn_generate);
     btn_Resend = (ImageButton) findViewById(R.id.btn_resend);


     btn_Generate.setOnClickListener(new OnClickListener() {
     @Override
     public void onClick(View v) 
     {
         String email = txt_Email.getText().toString();
         String employee = txt_Emp.getText().toString();

         //Hashcode
                         //this will get the hashcode


            //SENDING AN EMAIL
                              // this is for sending an email containing the hashcode


    btn_Submit.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
        //this will proceed to the next activity if the code is correct
            }   
                         }

This is my 2nd activity

public class WelcomeActivity extends Activity {

TextView txtWelcome;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_welcome);

    quit = (Button) findViewById(R.id.button1);

    quit.setOnClickListener(new OnClickListener() {
    public void onClick(View v) {

               //this button will direct to the 1st activity.

        }
        });
       }

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.welcome, menu);
    return true;
}
}

I want it that if the user did not click the user he would stay on the second activity even if he close the apps and if he click the return in emulator the apps will never gets back to the first activity. and i dont have any idea. Thank you very much.

我通过使用共享首选项解决了这个问题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM