Android:从以前的位置恢复应用程序

Doo*_*ght 9 android android-intent

如何从以前的位置恢复我的应用程序.

请注意,它仍处于活动状态,只是暂停了.因此,如果我单击androids当前应用程序按钮或应用程序图标,它将恢复正常.

但我是谁从我的小部件做到这一点..

我有以下内容:

// Create an Intent to launch Activity
Intent intent = new Intent(context, LoginForm.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
Run Code Online (Sandbox Code Playgroud)

这显然启动了LoginForm,而不仅仅是恢复应用程序.

有谁知道如何做到这一点?

编辑:

只是为了澄清,我不想要任何特别的东西.我基本上想模仿按下android图标启动器.

Dav*_*ser 17

你基本上回答了自己的问题;-)

只需模拟启动应用时Android的功能:

Intent intent = new Intent(context, LoginForm.class);
intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
Run Code Online (Sandbox Code Playgroud)

或者您可以尝试这个(假设LoginForm您的应用程序的根活动,并且在活动堆栈中仍有活动的实例):

Intent intent = new Intent(context, LoginForm.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
Run Code Online (Sandbox Code Playgroud)

设置FLAG_ACTIVITY_NEW_TASK 应该只为应用程序提供从后台到前台的现有任务,而不实际创建活动的实例.先试试这个.如果它对您不起作用,请执行另一个.