SingleInstance活动让我迷惑 [英] SingleInstance activity make me confuse

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

问题描述

一个活动是一个s​​ingleInstance活动。

A activity is a singleInstance Activity.

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

public class A extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setTitle("A");
        startActivity(new Intent(this, B.class));
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        testLog("new Intent A");
    }

    private void testLog(String string) {
        Log.d("test", string);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        testLog("destroy A");
    }
}

B的活性是一个标准的活动。

B activity is a standard activity.

在正常情况下,A-> B。用户操作回操作,和B摧毁。用户preSS回来,A消灭。这是正确的。

In the normal case A->B. User action back operation, and B destroy. User press back again, A destroy. That's correct.

但在其他情况下:A-> B。用户操作home键。当用户重启任务,Android框架调用A的 onNewIntent()

But in the other case: A->B. User action home button. When user restart task, the android framework calls A's onNewIntent().

为什么我的意思是活动栈应该喜欢这样:

Why?I mean the activity stack should like that:

-B
-A

意图为什么Android框架路线?A

Why does the android framework route the intent to A?

推荐答案

singleTop singleTask 之间的差异和 singleInstance 。读<一个href=\"http://developer.android.com/reference/android/R.styleable.html#AndroidManifestActivity_launchMode\"相对=nofollow>有关详细信息,文档,但你要注意的说明 singleInstance

There are differences between singleTop, singleTask and singleInstance. Read the documentation for more information, but you do want to note the description of singleInstance.

仅允许本次活动的一个实​​例永远运行。 此活动得到只有在自身运行它独特的任务;如果是以往任何时候都使用相同的意图再次启动,则该任务将被向前带来,并要求其Activity.onNewIntent()方法。如果这个活动试图启动一个新的活动,新的活动将在推出单独的任务。参阅有关任务的详细信息,任务和返回堆栈文件。

Only allow one instance of this activity to ever be running. This activity gets a unique task with only itself running in it; if it is ever launched again with the same Intent, then that task will be brought forward and its Activity.onNewIntent() method called. If this activity tries to start a new activity, that new activity will be launched in a separate task. See the Tasks and Back Stack document for more details about tasks.

这正是你所看到的,应该可以预期的行为。

This is exactly the behavior you're seeing and should be expected.

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

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