2016-10-19 6 views
0

私は最近私のテストに通知を追加しました。その中にはカウントダウンタイマーがあります。時間を選択してボタンをタップすると、通知はタイマーに設定され、動作します。通知がまだ実行されているときにホームボタンを押したときに通知をタップすると、実行中のアプリケーションではなく新しいアプリケーションのページに移動します。私がしようとしている修正は、通知がタップされたときにタイマーを停止し、ユーザーに自分のアプリケーションのリセットページを表示させることです。Notificatoin実行中のアプリへの意向

//Notification Intent 
    final Intent notifyIntent = new Intent(this , MainActivity.class); 
    final PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT); 
    final NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 



    View.OnClickListener listener = new View.OnClickListener() { 
     @Override 
     public void onClick(View view) { 



      if (view.equals(silentButton)) { 

       int getvaluehour = numPickerHour.getValue(); 
       int getvalueminute = numPickerMin.getValue(); 

       getvaluehour = getvaluehour * 3600000; 
       getvalueminute = getvalueminute * 60000; 
       long hoursandMinstomils = getvalueminute + getvaluehour; 



       final CountDownTimer counter = new CountDownTimer(hoursandMinstomils, 1000) { 


        public void onTick(long millisUntilFinished) { 
         //here you can have your logic to set text to edittext 
         long millis = millisUntilFinished; 
         //Convert milliseconds into hour,minute and seconds 
         String hms = String.format("Silent ends in: " + "%02d:%02d:%02d", TimeUnit.MILLISECONDS.toHours(millis), TimeUnit.MILLISECONDS.toMinutes(millis) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(millis)), TimeUnit.MILLISECONDS.toSeconds(millis) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millis))); 
         myText.setText(hms); 




         //Notification 
         notifyTimer.setSmallIcon(R.mipmap.ic_launcher); 
         notifyTimer.setTicker("This is a notification"); 
         notifyTimer.setAutoCancel(true); 
         notifyTimer.setContentTitle(hms); 

         //Notification Intent 
         notifyTimer.setContentIntent(pendingIntent); 

         //issues the notification 
         nm.notify(uniqueID, notifyTimer.build()); 

        } 




        public void onFinish() { 

         myText.setText("TIME'S UP!!"); //On finish change timer text 

         nm.cancel(uniqueID); 



        } 
       }.start(); 





       stopButton.setOnClickListener(
         new Button.OnClickListener() { 
          public void onClick(View v) { 
           counter.cancel(); 
           myText.setText("Timer has been reset"); 

           nm.cancel(uniqueID); 

          } 
         } 
       ); 



      } 
+0

を使用することができ、あなたの目的のために、その動作を設定するための意図にフラグを設定することができます:あなたの活動にlaunchMode =「singleTop」を –

+0

あなたが指定できますもっと具体的にお願いします –

+0

AndroidマニフェストファイルのMainActivityについては、このコードを追加する必要があります。アンドロイド:launchMode = "singleTop" –

答えて

0

、あなたがアンドロイドを追加する必要があり、この

notifyIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); 
+0

まだ新しい活動に私を得る実行しているe –

関連する問題