Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
531 views
in Technique[技术] by (71.8m points)

process - Android application Exit for home screen

I have develop android application,there I have Exit button in menu option.I want exit application and go to home screen when I press exit button. for that I have used following methods

1.System.exit(0)

2.finish()

3.android.os.Process.killProcess(android.os.Process.myPid())

4.System.runFinalizersOnExit(true);

these all methods direct to application my first page not to home screen.so what should I do for this?? please help me

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Firstly close in an android application is frowned upon because the back button and home button are already kinda giving you this functionality. But if you need to you can do this

When the user wishes to exit all open activities, they should press a button which loads the first Activity that runs when your app starts.

    Intent intent = new Intent(getApplicationContext(), FirstActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.putExtra("EXIT", true);
    startActivity(intent);

The above code clears all the activities except for first activity. Then put this code inside the first activity's onCreate(), to signal when it should self destruct when the 'Exit' message is passed.

    if (getIntent().getBooleanExtra("EXIT", false)) {
        finish();
    }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...