finish() finish the activity but it is still on background

余生长醉 提交于 2020-03-18 06:11:34

问题


I have a question concerning the finish() method of an activity in android studio:

I have this simple code:

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }
}

In my activity_main I simply have a button. When I click on the button the activity finishes and I go back to the main screen of the device...However, when I click on the menu button of the device (which shows all the app running in background) I still see my activity... and I do not want that. How can I fix it?


回答1:


try using

android:excludeFromRecents="true" in your Activity in AndroidManifest.xml.

<activity
            ...
             android:excludeFromRecents="true">
</activity>


来源:https://stackoverflow.com/questions/46254861/finish-finish-the-activity-but-it-is-still-on-background

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!