如何重新启动活动 [英] How to restart an activity

查看:169
本文介绍了如何重新启动活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个活动。我在清单文件中所做的发射模式为singleTask。我想DONOT同一活动的多个实例应该开始。我吃午饭的另一个活动按钮单击此活动。

如果我按一下按钮一次,然后为我做那么活动作为单个任务如果活动已运行,然后什么也没有发生更多。但我想重新开始活动,而无需创建另一个实例。如何实现这一点。

谢谢
迪帕克


解决方案

 但我要重新开始活动,而无需创建另一个实例

你的意思我重新开张,而无需创建。我想你可能已设置code你已经摆在你的的onCreate ,并要运行活动时再次得到了控制。如果是这样的你最好地方,code到你的 onResume onNewIntent 。由于单任务的onCreate将只执行一次,

singleTask 结果
系统将创建一个新的任务和路线的意图,它的根活动。但是,如果活动的一个实​​例已经存在,该系统通过航线对其onNewIntent()方法调用的意图,现有的实例,而不是创建一个新的。

I have created an activity. I made the launch mode as singleTask in manifest file. I donot want multiple instance of the same activity should start. I am lunching this activity on button click of another activity.

If i click the button more than once then as i have made the activity as single task then If the activity already running then nothing happens. But I want to relaunch the activity without creating another instance. How to achieve this.

Thanks Deepak

解决方案

But I want to relaunch the activity without creating another instance  

What you meant my relaunch without creating. I think you may have set of code that you have placed in your onCreate and you want to run when the activity again got control. If so its better for you to place that code to your onResume or onNewIntent. Because onCreate of the single task will only execute once

singleTask
The system creates the activity at the root of a new task and routes the intent to it. However, if an instance of the activity already exists, the system routes the intent to existing instance through a call to its onNewIntent() method, rather than creating a new one.

这篇关于如何重新启动活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆