2013-05-15 2 views
4

보류중인 의도가있는 추가 문자열을 내 StateCh.java에서 MainActivity으로 보냅니다. 그것에 대한 나의 기대는 추가로 보류 된 의도가 도착할 때 (알림을 클릭 할 때) MainActivity에 대화 상자를 표시하는 것입니다. 문제는 내가 MainActivity을 연 다음 보류중인 인 텐트 내부에 추가 정보가없고 대화 상자가 표시되지 않는다는 알림을 클릭하는 경우입니다. MainActivity (뒤로 단추를 눌러서)을 일시 중지하고 알림을 다시 누르면 예상대로 작동합니다.보류중인 인트 트 엑스트라는 작업이 일시 중지 된 경우에만 수신됩니다.

MainActivity.java :

public class MainActivity extends Activity { 

//... 

    @Override 
protected void onNewIntent(Intent intent) { 
    super.onNewIntent(intent); 

    Bundle extras = getIntent().getExtras(); 
    if(extras !=null) { 
     String value1 = extras.getString("message"); 
     Log.v("alert", value1); 

     AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create(); 
     alertDialog.setTitle("title"); 
     alertDialog.setMessage(value1); 
     alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "OK", new DialogInterface.OnClickListener() { 

      public void onClick(DialogInterface dialog, int which) { 

       //startActivity(MainActivity.this.getIntent()); 

      } 
     }); 

     alertDialog.show(); 
    } 
} 
} 

StateCh.java :

public class StateCh extends Service { 

//... 

    private void notificationU(String title, String text) { 

    //The intent to launch when the user clicks the expanded notification 
    Intent intent = new Intent(this, MainActivity.class); 
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); 
    intent.putExtra("message", "something"); 
    intent.setAction("actionstring" + System.currentTimeMillis()); 

    PendingIntent pendIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); 

    Notification noti2 = new NotificationCompat.Builder(this) 
    .setContentTitle(title) 
    .setContentText(text) 
    .setSmallIcon(R.drawable.warning) 
    .setContentIntent(pendIntent) 
    .build(); 

    mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
    mNotificationManager.notify(123456, noti2); 
    } 

    // ...  

} 

답변

5

변경 Bundle extras = getIntent().getExtras();

Bundle extras = intent.getExtras();으로

또는 전화 setIntent(intent)

+0

감사! 나는 그것이 매우 간단하다는 것을 믿을 수는 없지만 트릭을했습니다. – Kristopher

관련 문제