如何退出应用程序并显示主屏幕?

时间:2023-01-22 23:13:17

I have an application where on the home page I have buttons for navigation through the application.

我有一个应用程序,在主页上有用于在应用程序中导航的按钮。

On that page I have a button "EXIT" which when clicked should take the user to the home screen on the phone where the application icon is.

在那个页面上,我有一个“退出”按钮,当用户点击时,该按钮会将用户带到应用程序图标所在的手机的主屏幕上。

How can I do that?

我怎么做呢?

17 个解决方案

#1


306  

Android's design does not favor exiting an application by choice, but rather manages it by the OS. You can bring up the Home application by its corresponding Intent:

Android的设计不支持选择退出应用程序,而是通过操作系统管理它。你可按其相应的目的提出家居申请:

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

#2


71  

May be you can try something like this

你可以试试这个吗?

Suppose in our application, we have a number of activities(say ten) and we need to exit directly from this activity. What we can do is, create an intent and go to the root activity and set flag in the intent as

假设在我们的应用程序中,我们有很多活动(比如10个),我们需要直接退出这个活动。我们可以做的是,创建一个意图,然后到根活动并在意图中设置标志为

intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

also, add some extra like boolean to the intent

另外,在意图中添加一些额外的布尔值。

intent.putExtra("EXIT", true);

Then in root activity, check the value of the boolean and according to that call finish(), in the onCreate() of the root activity

然后在根活动中,根据调用finish(),在根活动的onCreate()中检查布尔值

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

#3


26  

System.exit(0);

Is probably what you are looking for. It will close the entire application and take you to the home Screen.

这可能就是你要找的。它将关闭整个应用程序并将您带到主屏幕。

#4


23  

This works well for me.
Close all the previous activities as follows:

这对我很有效。关闭之前所有活动如下:

    Intent intent = new Intent(this, MainActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.putExtra("Exit me", true);
    startActivity(intent);
    finish();

Then in MainActivity onCreate() method add this to finish the MainActivity

然后在MainActivity onCreate()方法中添加这个以完成主活动

    setContentView(R.layout.main_layout);

    if( getIntent().getBooleanExtra("Exit me", false)){
        finish();
        return; // add this to prevent from doing unnecessary stuffs
    }

#5


22  

first finish your application using method finish();

首先使用方法finish()完成应用程序;

and then add below lines in onDestroy for Removing Force close

然后在onDestroy中增加以下线条,以消除关闭的力

android.os.Process.killProcess(android.os.Process.myPid());
super.onDestroy();

#6


19  

If you want to end an activity you can simply call finish(). It is however bad practice to have an exit button on the screen.

如果希望结束活动,可以简单地调用finish()。然而,在屏幕上设置退出按钮是不好的做法。

#7


16  

It is not recommended to exit your Android Application. See this question for more details.

不建议退出Android应用程序。更多细节请看这个问题。

The user can always quit your app through the home button or in the first activity through the back button.

用户总是可以通过home按钮退出应用程序,或者通过back按钮退出第一个活动。

#8


16  

Some Activities actually you don't want to open again when back button pressed such Splash Screen Activity, Welcome Screen Activity, Confirmation Windows. Actually you don't need this in activity stack. you can do this using=> open manifest.xml file and add a attribute

有些活动实际上您不想再次打开,当后退按钮按下这样的启动屏幕活动,欢迎屏幕活动,确认窗口。实际上,在活动堆栈中不需要这个。您可以使用=>打开清单。xml文件并添加一个属性。

android:noHistory="true"

android:noHistory = " true "

to these activities.

这些活动。

<activity
    android:name="com.example.shoppingapp.AddNewItems"
    android:label="" 
    android:noHistory="true">
</activity>

OR

Sometimes you want close the entire application in certain back button press. Here best practice is open up the home window instead of exiting application. For that you need to override onBackPressed() method. usually this method open up the top activity in the stack.

有时您想要关闭整个应用程序在特定的后退按钮按下。这里的最佳实践是打开主窗口而不是退出应用程序。为此,需要重写onBackPressed()方法。通常,该方法打开堆栈中的顶部活动。

@Override
public void onBackPressed(){
Intent a = new Intent(Intent.ACTION_MAIN);
a.addCategory(Intent.CATEGORY_HOME);
a.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(a);

}

OR

In back button pressed you want to exit that activity and also you also don't want to add this in activity stack. call finish() method inside onBackPressed() method. it will not make close the entire application. it will go for the previous activity in the stack.

在后退按钮中,你想要退出那个活动,而且你也不想在活动堆栈中添加这个。调用onBackPressed()方法中的finish()方法。它不会关闭整个应用程序。它将用于堆栈中的前一个活动。

@Override
public void onBackPressed() {
  finish();
}

#9


5  

(I tried previous answers but they lacks in some points. For example if you don't do a return; after finishing activity, remaining activity code runs. Also you need to edit onCreate with return. If you doesn't run super.onCreate() you will get a runtime error)

(我试过之前的答案,但有些地方没有。例如,如果你不返回;完成活动后,运行其余的活动代码。还需要用return编辑onCreate。如果不运行super.onCreate(),就会出现运行时错误)

Say you have MainActivity and ChildActivity.

假设你有主要活动和孩子活动。

Inside ChildActivity add this:

内部ChildActivity添加:

Intent intent = new Intent(ChildActivity.this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("EXIT", true);
startActivity(intent);
return true;

Inside MainActivity's onCreate add this:

在MainActivity的onCreate中添加这个:

@Override
public void onCreate(Bundle savedInstanceState) {

    mContext = getApplicationContext();

    super.onCreate(savedInstanceState);

    if (getIntent().getBooleanExtra("EXIT", false)) {
        finish();
        return;
    }
    // your current codes
    // your current codes
}

#10


4  

There is another option, to use the FinishAffinity method to close all the tasks in the stack related to the app.

还有另一个选项,使用FinishAffinity方法关闭与应用程序相关的堆栈中的所有任务。

See: https://*.com/a/27765687/1984636

参见:https://*.com/a/27765687/1984636

#11


3  

When u call finish onDestroy() of that activity will be called and it will go back to previous activity in the activity stack... So.. for exit do not call finish();

当您调用该活动的finish onDestroy()时,它将返回到活动堆栈中的先前活动……所以. .退出时不调用finish();

#12


1  

Here's what i did:

这是我所做的:

SomeActivity.java

SomeActivity.java

 @Override
    public void onBackPressed() {
            Intent newIntent = new Intent(this,QuitAppActivity.class);
            newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(newIntent);
            finish();
    }

QuitAppActivity.java

QuitAppActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      finish();
}

Basically what you did is cleared all activities from the stack and launch QuitAppActivity, whose only job is to quit the application.

基本上,您所做的是清除堆栈中的所有活动,并启动QuitAppActivity,其惟一的工作就是退出应用程序。

#13


0  

Add following lines after finish(); in onDestroy():

在完成后添加以下行();在onDestroy():

android.os.Process.killProcess(android.os.Process.myPid());
super.onDestroy();

#14


0  

I tried exiting application using following code snippet, this it worked for me. Hope this helps you. i did small demo with 2 activities

我尝试使用以下代码片段退出应用程序,这对我很有效。希望这能帮助你。我做了2个小演示

first activity

第一个活动

public class MainActivity extends Activity implements OnClickListener{
    private Button secondActivityBtn;
    private SharedPreferences pref;
    private SharedPreferences.Editor editer;

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

        secondActivityBtn=(Button) findViewById(R.id.SecondActivityBtn);
        secondActivityBtn.setOnClickListener(this);

        pref = this.getSharedPreferences("MyPrefsFile", MODE_PRIVATE);
        editer = pref.edit();

        if(pref.getInt("exitApp", 0) == 1){
            editer.putInt("exitApp", 0);
            editer.commit();
            finish();
        }
    }
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
        case R.id.SecondActivityBtn:
            Intent intent= new Intent(MainActivity.this, YourAnyActivity.class);
            startActivity(intent);
            break;
        default:
            break;
        }
    }
}

your any other activity

你的任何其他活动

public class YourAnyActivity extends Activity implements OnClickListener {
    private Button exitAppBtn;
    private SharedPreferences pref;
    private SharedPreferences.Editor editer;

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

        exitAppBtn = (Button) findViewById(R.id.exitAppBtn);
        exitAppBtn.setOnClickListener(this);

        pref = this.getSharedPreferences("MyPrefsFile", MODE_PRIVATE);
        editer = pref.edit();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
        case R.id.exitAppBtn:
            Intent main_intent = new Intent(YourAnyActivity.this,
                    MainActivity.class);
            main_intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(main_intent);
            editer.putInt("exitApp",1);
            editer.commit();
            break;
        default:
            break;
        }
    }
}

#15


0  

I did it with observer mode.

我用的是观察者模式。

Observer interface

观察者接口

public interface Observer {
public void update(Subject subject);
}

Base Subject

基础学科

public class Subject {
private List<Observer> observers = new ArrayList<Observer>();

public void attach(Observer observer){
    observers.add(observer);
}

public void detach(Observer observer){
    observers.remove(observer);
}

protected void notifyObservers(){
    for(Observer observer : observers){
        observer.update(this);
    }
}
}

Child Subject implements the exit method

子主题实现了退出方法

public class ApplicationSubject extends Subject {
public void exit(){
    notifyObservers();
}
}

MyApplication which your application should extends it

应用程序应该扩展的MyApplication

public class MyApplication extends Application {

private static ApplicationSubject applicationSubject;

public ApplicationSubject getApplicationSubject() {
            if(applicationSubject == null) applicationSubject = new ApplicationSubject();
    return applicationSubject;
}

}

}

Base Activity

基本活动

public abstract class BaseActivity extends Activity implements Observer {

public MyApplication app;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    app = (MyApplication) this.getApplication();
    app.getApplicationSubject().attach(this);
}

@Override
public void finish() {
    // TODO Auto-generated method stub
            app.getApplicationSubject().detach(this);
    super.finish();
}

/**
 * exit the app
 */
public void close() {
    app.getApplicationSubject().exit();
};

@Override
public void update(Subject subject) {
    // TODO Auto-generated method stub
    this.finish();
}

}

let's test it

让我们做个测试

public class ATestActivity extends BaseActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    close(); //invoke 'close'
}
}

#16


0  

if you want to exit application put this code under your function

如果要退出应用程序,请将此代码放在函数下

public void yourFunction()
{
finishAffinity();   
moveTaskToBack(true);

}



//For an instance, if you want to exit an application on double click of a 
//button,then the following code can be used.
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)  {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 2) {
        // do something on back.
        From Android 16+ you can use the following:

        finishAffinity();
        moveTaskToBack(true);
    }

    return super.onKeyDown(keyCode, event);
}

#17


-2  

If you want to exit from your application. Then use this code inside your button pressed event. like:

如果您想要退出应用程序。然后在按钮按下事件中使用此代码。如:

public void onBackPressed()
{
    moveTaskToBack(true);
    android.os.Process.killProcess(android.os.Process.myPid());
    System.exit(1);
}

#1


306  

Android's design does not favor exiting an application by choice, but rather manages it by the OS. You can bring up the Home application by its corresponding Intent:

Android的设计不支持选择退出应用程序,而是通过操作系统管理它。你可按其相应的目的提出家居申请:

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

#2


71  

May be you can try something like this

你可以试试这个吗?

Suppose in our application, we have a number of activities(say ten) and we need to exit directly from this activity. What we can do is, create an intent and go to the root activity and set flag in the intent as

假设在我们的应用程序中,我们有很多活动(比如10个),我们需要直接退出这个活动。我们可以做的是,创建一个意图,然后到根活动并在意图中设置标志为

intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

also, add some extra like boolean to the intent

另外,在意图中添加一些额外的布尔值。

intent.putExtra("EXIT", true);

Then in root activity, check the value of the boolean and according to that call finish(), in the onCreate() of the root activity

然后在根活动中,根据调用finish(),在根活动的onCreate()中检查布尔值

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

#3


26  

System.exit(0);

Is probably what you are looking for. It will close the entire application and take you to the home Screen.

这可能就是你要找的。它将关闭整个应用程序并将您带到主屏幕。

#4


23  

This works well for me.
Close all the previous activities as follows:

这对我很有效。关闭之前所有活动如下:

    Intent intent = new Intent(this, MainActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.putExtra("Exit me", true);
    startActivity(intent);
    finish();

Then in MainActivity onCreate() method add this to finish the MainActivity

然后在MainActivity onCreate()方法中添加这个以完成主活动

    setContentView(R.layout.main_layout);

    if( getIntent().getBooleanExtra("Exit me", false)){
        finish();
        return; // add this to prevent from doing unnecessary stuffs
    }

#5


22  

first finish your application using method finish();

首先使用方法finish()完成应用程序;

and then add below lines in onDestroy for Removing Force close

然后在onDestroy中增加以下线条,以消除关闭的力

android.os.Process.killProcess(android.os.Process.myPid());
super.onDestroy();

#6


19  

If you want to end an activity you can simply call finish(). It is however bad practice to have an exit button on the screen.

如果希望结束活动,可以简单地调用finish()。然而,在屏幕上设置退出按钮是不好的做法。

#7


16  

It is not recommended to exit your Android Application. See this question for more details.

不建议退出Android应用程序。更多细节请看这个问题。

The user can always quit your app through the home button or in the first activity through the back button.

用户总是可以通过home按钮退出应用程序,或者通过back按钮退出第一个活动。

#8


16  

Some Activities actually you don't want to open again when back button pressed such Splash Screen Activity, Welcome Screen Activity, Confirmation Windows. Actually you don't need this in activity stack. you can do this using=> open manifest.xml file and add a attribute

有些活动实际上您不想再次打开,当后退按钮按下这样的启动屏幕活动,欢迎屏幕活动,确认窗口。实际上,在活动堆栈中不需要这个。您可以使用=>打开清单。xml文件并添加一个属性。

android:noHistory="true"

android:noHistory = " true "

to these activities.

这些活动。

<activity
    android:name="com.example.shoppingapp.AddNewItems"
    android:label="" 
    android:noHistory="true">
</activity>

OR

Sometimes you want close the entire application in certain back button press. Here best practice is open up the home window instead of exiting application. For that you need to override onBackPressed() method. usually this method open up the top activity in the stack.

有时您想要关闭整个应用程序在特定的后退按钮按下。这里的最佳实践是打开主窗口而不是退出应用程序。为此,需要重写onBackPressed()方法。通常,该方法打开堆栈中的顶部活动。

@Override
public void onBackPressed(){
Intent a = new Intent(Intent.ACTION_MAIN);
a.addCategory(Intent.CATEGORY_HOME);
a.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(a);

}

OR

In back button pressed you want to exit that activity and also you also don't want to add this in activity stack. call finish() method inside onBackPressed() method. it will not make close the entire application. it will go for the previous activity in the stack.

在后退按钮中,你想要退出那个活动,而且你也不想在活动堆栈中添加这个。调用onBackPressed()方法中的finish()方法。它不会关闭整个应用程序。它将用于堆栈中的前一个活动。

@Override
public void onBackPressed() {
  finish();
}

#9


5  

(I tried previous answers but they lacks in some points. For example if you don't do a return; after finishing activity, remaining activity code runs. Also you need to edit onCreate with return. If you doesn't run super.onCreate() you will get a runtime error)

(我试过之前的答案,但有些地方没有。例如,如果你不返回;完成活动后,运行其余的活动代码。还需要用return编辑onCreate。如果不运行super.onCreate(),就会出现运行时错误)

Say you have MainActivity and ChildActivity.

假设你有主要活动和孩子活动。

Inside ChildActivity add this:

内部ChildActivity添加:

Intent intent = new Intent(ChildActivity.this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("EXIT", true);
startActivity(intent);
return true;

Inside MainActivity's onCreate add this:

在MainActivity的onCreate中添加这个:

@Override
public void onCreate(Bundle savedInstanceState) {

    mContext = getApplicationContext();

    super.onCreate(savedInstanceState);

    if (getIntent().getBooleanExtra("EXIT", false)) {
        finish();
        return;
    }
    // your current codes
    // your current codes
}

#10


4  

There is another option, to use the FinishAffinity method to close all the tasks in the stack related to the app.

还有另一个选项,使用FinishAffinity方法关闭与应用程序相关的堆栈中的所有任务。

See: https://*.com/a/27765687/1984636

参见:https://*.com/a/27765687/1984636

#11


3  

When u call finish onDestroy() of that activity will be called and it will go back to previous activity in the activity stack... So.. for exit do not call finish();

当您调用该活动的finish onDestroy()时,它将返回到活动堆栈中的先前活动……所以. .退出时不调用finish();

#12


1  

Here's what i did:

这是我所做的:

SomeActivity.java

SomeActivity.java

 @Override
    public void onBackPressed() {
            Intent newIntent = new Intent(this,QuitAppActivity.class);
            newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(newIntent);
            finish();
    }

QuitAppActivity.java

QuitAppActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      finish();
}

Basically what you did is cleared all activities from the stack and launch QuitAppActivity, whose only job is to quit the application.

基本上,您所做的是清除堆栈中的所有活动,并启动QuitAppActivity,其惟一的工作就是退出应用程序。

#13


0  

Add following lines after finish(); in onDestroy():

在完成后添加以下行();在onDestroy():

android.os.Process.killProcess(android.os.Process.myPid());
super.onDestroy();

#14


0  

I tried exiting application using following code snippet, this it worked for me. Hope this helps you. i did small demo with 2 activities

我尝试使用以下代码片段退出应用程序,这对我很有效。希望这能帮助你。我做了2个小演示

first activity

第一个活动

public class MainActivity extends Activity implements OnClickListener{
    private Button secondActivityBtn;
    private SharedPreferences pref;
    private SharedPreferences.Editor editer;

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

        secondActivityBtn=(Button) findViewById(R.id.SecondActivityBtn);
        secondActivityBtn.setOnClickListener(this);

        pref = this.getSharedPreferences("MyPrefsFile", MODE_PRIVATE);
        editer = pref.edit();

        if(pref.getInt("exitApp", 0) == 1){
            editer.putInt("exitApp", 0);
            editer.commit();
            finish();
        }
    }
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
        case R.id.SecondActivityBtn:
            Intent intent= new Intent(MainActivity.this, YourAnyActivity.class);
            startActivity(intent);
            break;
        default:
            break;
        }
    }
}

your any other activity

你的任何其他活动

public class YourAnyActivity extends Activity implements OnClickListener {
    private Button exitAppBtn;
    private SharedPreferences pref;
    private SharedPreferences.Editor editer;

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

        exitAppBtn = (Button) findViewById(R.id.exitAppBtn);
        exitAppBtn.setOnClickListener(this);

        pref = this.getSharedPreferences("MyPrefsFile", MODE_PRIVATE);
        editer = pref.edit();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
        case R.id.exitAppBtn:
            Intent main_intent = new Intent(YourAnyActivity.this,
                    MainActivity.class);
            main_intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(main_intent);
            editer.putInt("exitApp",1);
            editer.commit();
            break;
        default:
            break;
        }
    }
}

#15


0  

I did it with observer mode.

我用的是观察者模式。

Observer interface

观察者接口

public interface Observer {
public void update(Subject subject);
}

Base Subject

基础学科

public class Subject {
private List<Observer> observers = new ArrayList<Observer>();

public void attach(Observer observer){
    observers.add(observer);
}

public void detach(Observer observer){
    observers.remove(observer);
}

protected void notifyObservers(){
    for(Observer observer : observers){
        observer.update(this);
    }
}
}

Child Subject implements the exit method

子主题实现了退出方法

public class ApplicationSubject extends Subject {
public void exit(){
    notifyObservers();
}
}

MyApplication which your application should extends it

应用程序应该扩展的MyApplication

public class MyApplication extends Application {

private static ApplicationSubject applicationSubject;

public ApplicationSubject getApplicationSubject() {
            if(applicationSubject == null) applicationSubject = new ApplicationSubject();
    return applicationSubject;
}

}

}

Base Activity

基本活动

public abstract class BaseActivity extends Activity implements Observer {

public MyApplication app;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    app = (MyApplication) this.getApplication();
    app.getApplicationSubject().attach(this);
}

@Override
public void finish() {
    // TODO Auto-generated method stub
            app.getApplicationSubject().detach(this);
    super.finish();
}

/**
 * exit the app
 */
public void close() {
    app.getApplicationSubject().exit();
};

@Override
public void update(Subject subject) {
    // TODO Auto-generated method stub
    this.finish();
}

}

let's test it

让我们做个测试

public class ATestActivity extends BaseActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    close(); //invoke 'close'
}
}

#16


0  

if you want to exit application put this code under your function

如果要退出应用程序,请将此代码放在函数下

public void yourFunction()
{
finishAffinity();   
moveTaskToBack(true);

}



//For an instance, if you want to exit an application on double click of a 
//button,then the following code can be used.
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)  {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 2) {
        // do something on back.
        From Android 16+ you can use the following:

        finishAffinity();
        moveTaskToBack(true);
    }

    return super.onKeyDown(keyCode, event);
}

#17


-2  

If you want to exit from your application. Then use this code inside your button pressed event. like:

如果您想要退出应用程序。然后在按钮按下事件中使用此代码。如:

public void onBackPressed()
{
    moveTaskToBack(true);
    android.os.Process.killProcess(android.os.Process.myPid());
    System.exit(1);
}