如何杀死一个活动

发布于 2024-12-08 18:48:07 字数 708 浏览 0 评论 0原文

我有一个启动屏幕、一个GridView、一个简单文本视图

在应用程序启动时,我显示启动屏幕,然后调用“finish()”退出活动,然后启动“GridView”活动。

1st page: Grid View having 4 buttons, let's call it Home page..
2nd page: On click of 1st button, SAME grid view is called. But this time, there are 5 buttons.
3rd page: On click of 1st button, same grid view is called. This time there are 3 buttons.
4th page: On click of 1st button, it opens a simple text view, which has a text box and an "Home" button.

在主页上,当我单击后退按钮时,我希望应用程序退出或关闭... 但由于第一页、第二页、第三页仍在堆栈中,我不能直接退出应用程序。

在我的主屏幕上,如果我点击平板电脑的“主页”按钮,应用程序就会退出。当我从“应用程序”选项再次启动应用程序时,将显示之前显示的屏幕,而不是启动屏幕!

我希望它显示启动画面。

I have a splash screen, a GridView, a simple text view.

On application start, I show the splash screen after which i call "finish()" to exit the activity and then start the "GridView" activity.

1st page: Grid View having 4 buttons, let's call it Home page..
2nd page: On click of 1st button, SAME grid view is called. But this time, there are 5 buttons.
3rd page: On click of 1st button, same grid view is called. This time there are 3 buttons.
4th page: On click of 1st button, it opens a simple text view, which has a text box and an "Home" button.

On home page, when i click the back button, I want the application to exit, or close...
But since the 1st, 2nd, 3rd page are still in the stack, I cannot just exit the application.

On my home screen, if i hit the "home" button of the tablet, the application exits. When i start the application again from the "Apps" option, the previously present screen is shown and not the splash screen!!!

I want it to show the splash screen.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

吹梦到西洲 2024-12-15 18:48:07

启动 Activity 时尝试使用 FLAG_ACTIVITY_NEW_TASK

try to use FLAG_ACTIVITY_NEW_TASK when you start the activity.

愿与i 2024-12-15 18:48:07

使用调用新屏幕

Intent intent = new Intent(activity,secondActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
activity.startActivity(intent);

当您点击主页按钮时,应用程序将恢复。所以下次它打开同一页面。对于重新启动时的此用途

@Override
protected void onRestart() {
    // TODO Auto-generated method stub
    super.onRestart();
    startActivity(new Intent(Activity1.this,spalshscreen.class));
}

,如果 Activity 在堆栈中,您还可以使用 Intent.FLAG_ACTIVITY_CLEAR_TOP 重置标志。

Call new screen using

Intent intent = new Intent(activity,secondActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
activity.startActivity(intent);

When you hit home button , application get resume. so next time it open the same page. for this use

@Override
protected void onRestart() {
    // TODO Auto-generated method stub
    super.onRestart();
    startActivity(new Intent(Activity1.this,spalshscreen.class));
}

on restarting , you can also reset flag using Intent.FLAG_ACTIVITY_CLEAR_TOP if activity is in stack.

扎心 2024-12-15 18:48:07

在该 Activity 的清单中使用启动模式作为单个任务

单击此处获取理解启动模式

use Launch mode in manifest for that Activity as single Task

Click Here to Get Uunderstanding For Launch Modes

云醉月微眠 2024-12-15 18:48:07

在您的活动中尝试此代码 -

@Override
protected void onDestroy() {
   android.os.Process.killProcess(android.os.Process.myPid());
}

当您退出应用程序时,您的应用程序进程实际上并未被销毁。如果你销毁你的进程,所有子进程(你的所有子线程)都将被销毁。

try this code in your activity -

@Override
protected void onDestroy() {
   android.os.Process.killProcess(android.os.Process.myPid());
}

When you exit from your application, your application process is not actually destroyed. If you destroy your process, all child processes(all your child threads) will be destroyed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文