Android的:从开始“最近的应用程序”应用程序启动时,它的最后一组额外的意图使用应用程序、它的、启动时、意图

由网友(初夏那抹浅蓝)分享简介:的混乱问题位,我在这里:Bit of a confusing problem for me here:我有一个主屏幕小工具,点击后,开始我主要的应用程序的活动与投入的意图做出一些:I've got a home screen widget which, when clicked, starts my main a...

的混乱问题位,我在这里:

Bit of a confusing problem for me here:

我有一个主屏幕小工具,点击后,开始我主要的应用程序的活动与投入的意图做出一些:

I've got a home screen widget which, when clicked, starts my main app Activity with a few extras put in the intent:

Intent start = new Intent(context, Main.class);
start.putExtra("action", "showXYZ");
start.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(start);

这一切工作正常,就开始我的活动我的活动受到了群众演员的预期。它处理这些额外并开始其他活动。

This all works fine, it starts my activity and my activity receives the extras as expected. It processes these extras and starts another activity.

一旦用户点击主屏幕小部件,并开始在主要业务以这种方式,进入应用程序通过最近的应用程序的方法(按住主页键)开始与额外的主要活动 - 导致处理发生,我不希望(并以领先第二名活动打开,而不是为主要业务,只是显示)。

Once a user has clicked the home screen widget and started the Main activity in this way, going into the app through the 'Recent applications' method (holding down the 'home' key) starts the Main activity with the extras - causing processing to happen which I don't want (and leading to the second activity to open, rather than for the Main activity to just be shown).

有没有变通的呢?当开始从最近的应用程序的方法的应用程序,我想简单地启动主要业务没有最后一组的群众演员。

Is there any work-around for this? When starting the app from the 'recent applications' method, I want to simply start the Main activity without the last set of extras.

非常感谢您的帮助! r3mo

Many thanks for the help! r3mo

注:我在Android 1.5

Note: I'm on android 1.5

编辑:

找到一个解决办法在这里: Android不断缓存我的意图附加功能,如何声明挂起的意图,保持新鲜的演员?

Found a workaround here: Android keeps caching my intents Extras, how to declare a pending intent that keeps fresh extras?

我要时间戳的意图正在掀起的小部件,并检查时间戳是最近在Main.java。如果是这样,我会继续进行处理。如果没有,我会只显示Main.java活动。

I'm going to timestamp the intent being set off by the widget, and check that the timestamp is recent in Main.java. If it is, i'll proceed with the processing. If not, i'll just show the Main.java activity.

敏锐地听到,如果有任何官方的解决方案了这一点。

Keen to hear if there are any official solutions to this.

推荐答案

由于马亭说,你可以检查你的应用程序正在使用的意图与标志打开 FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY 集,像这样的:

As Martijn says, you can check if your application is opened using an Intent with the flag FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY set, like this:

int flags = getActivity().getIntent().getFlags();       
if ((flags & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) != 0) {
    // The activity was launched from history
}
阅读全文

相关推荐

最新文章