用意图将活动带到前面

时间:2013-11-14 15:53:01

标签: java android android-intent

HY,

我正在制作一个简单的秒表。单击“开始”按钮时,状态栏中会显示通知。当我点击通知时,我的秒表停止,并重置为0。 这是通知的意图:

            Intent msgIntent = new Intent(this, myActivity.class);
            msgIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
            PendingIntent intent = PendingIntent.getActivity(myActivity.this,
                    0, msgIntent,
                    Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);

3 个答案:

答案 0 :(得分:0)

如果添加Flag没有按预期工作,那么实现您需要的最简单方法是在清单文件中定义特定Activity的launchMode。例如:

<activity
        android:name=".myActivity"
        android:label="@string/app_name"
        android:launchMode="singleTop" >

答案 1 :(得分:0)

尝试以下假人:

        Intent msgIntent = new Intent(this, myActivity.class);
        msgIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
        msgIntent.putExtas(STOP, true);
        PendingIntent intent = PendingIntent.getActivity(myActivity.this,
                0, msgIntent,
                PendingIntent.FLAG_CANCEL_CURRENT);

       //In your activity:
       onCreate() {
           if( getIntent().getBoolean(STOP) ) 
               then stop
       }

       onNewIntent(Intent _intent) {
          if( _intent.getBoolean(STOP) ) 
               then stop
       }

答案 2 :(得分:0)

我使用这种方法,问题得到了解决,希望这对你也有帮助;

Intent intent = new Intent(Intent.ACTION_MAIN);

intent.addCategory(Intent.CATEGORY_LAUNCHER);

intent.setClass(this, Main.class);

intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
相关问题