结算活动栈只用一个preSSpreSS

由网友(看戏不入戏わ。)分享简介:我有一个启动活动 A1其中有一个启动按钮,启动服务 S1:I have a launching Activity A1 which has a start button which starts a Service S1:startButton.setOnClickListener(new View.OnClick...

我有一个启动活动 A1其中有一个启动按钮,启动服务 S1:

I have a launching Activity A1 which has a start button which starts a Service S1:

startButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {

                Log.i(TAG1, "Starting Update Service");
                startService(serviceIntentS1);
            }
        });

S1取决于一些条件开始活动 A2:

if (giveninteger>=2)
       {   
           Intent intentA2= new Intent(this, A2.class);
           // following line to avoid exception
           intentA2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); //to avoid exception
           startActivity(intentA2);  

         }

A2订阅S1和A2的用户可以看到S1的帮助下定期更新数据。 A2有以下code停止S1的服务:

A2 subscribes to S1 and from A2 user can see periodically updated data by the aid of S1. A2 has following code to stop S1 service:

public void onBackPressed() {
        try {
            Log.i(TAG2, "Killing Update Service");
            stopService(serviceIntentS1);

              } catch (NullPointerException e) {
            Log.i(TAG3, "Service was not running " + e.toString());
        }
        finish();
        System.exit(0);
        return;
    }  

我的问题是,如果更新运行10次从A2,用户必须preSS后退按钮10次以退出活动 A2。这是A2的情况下,累积在活动堆栈。我尝试了所有的标志,从S1推出A2的过程中,但没有成功。我想退出活动 A2只用一个回preSS,无论是更新运行多少次。

My problem is that, if the update runs 10 times from A2, user has to press back button 10 times to exit Activity A2. That is instances of A2 are accumulated in Activity stack. I tried all flags during launch of A2 from S1, but without success. I want to exit the Activity A2 with just one back press, no matter how many times the update runs.

任何建议会有所帮助。

Any suggestions would help.

推荐答案

你需要的是A2的SingleInstance,这样不论数量乘以A2推出只有一个实例的保持,你只需要preSS后退按钮一旦。 定义这个属性在AndroidManifest文件。

What you need is a SingleInstance of A2 so that irrespective of the number times A2 is launched only one instance remains and you need to press back button only once. Define this attribute in the AndroidManifest file.

<activity android:launchMode"singleInstance"/>
阅读全文

相关推荐

最新文章