2016-05-04 15 views
0

通知をクリックするとタイマーアプリを開きたい。私はすでに以下のコードを試していますが、新しいアクティビティを開始しています。私は既に実行している活動を開始したい。通知アクションで実行中のアクティビティを開くにはどうすればよいですか?

Intent intent = new Intent(timer.this, timer.class); 
PendingIntent pIntent = PendingIntent.getActivity(timer.this, 0, intent, 0); 

notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); 
notification = new Notification.Builder(timer.this) 
         .setSmallIcon(R.mipmap.ic_launcher) 
         .setContentIntent(pIntent) 
         .setContentTitle(clickedinterval) 
         .setContentText("Pause" + " Time remaining: " + minutesPauseCountDown + ":" + secondsPauseCountDown) 
         .build(); 

notification.flags = Notification.FLAG_ONGOING_EVENT | Notification.DEFAULT_LIGHTS; 

notificationManager.notify(0, notification); 
+0

を試すことができますか? –

答えて

0
in your case use android:launchMode="singleInstance" in mainfest file 
Or 
Intent.FLAG_ACTIVITY_NEW_TASK 


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

もcoding-に関するご質問、なぜあなたは小さな文字でJavaクラス名を維持している

Intent intent = new Intent(Timer.this, Timer.class); 
       intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); 
       PendingIntent pIntetn = PendingIntent.getActivity(timer.this, 0, intent, 0); 

       notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); 
       notification = new Notification.Builder(timer.this) 
         .setSmallIcon(R.mipmap.ic_launcher) 
         .setContentIntent(pIntetn) 
         .setContentTitle(clickedinterval) 
         .setContentText("Pause" + " Time remaining: " + minutesPauseCountDown + ":" + secondsPauseCountDown) 
         .build(); 

       notification.flags = Notification.FLAG_ONGOING_EVENT | Notification.DEFAULT_LIGHTS; 

       notificationManager.notify(0, notification); 
+0

コーディングに関する質問 - Javaクラス名を小文字にしているのはなぜですか?申し訳ありません質問は主人のためだった –

+0

は動作しませんでした –

関連する問題