1

서비스에서 알림을 보내려고하고 있는데, 그 것이 성공하면 (상태 표시 줄에 알림이 표시됩니다). 하지만 활동을보기 위해 알림을 클릭 한 후 - 모바일 홈 화면으로 돌아갑니다. 또한 디버깅 모드에서 activity의 "onCreate"메서드에 도달하지 못했다는 것을 알았습니다. 여기 서비스에서 알림이 작동하지만 작업이 시작되지 않았습니다.

의 코드 내 조각 : 서비스 코드 :

NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 
    int icon = R.drawable.notificationicon; 
    CharSequence tickerText = "Hello"; 
    long when = System.currentTimeMillis(); 

    Notification notification = new Notification(icon, tickerText, when); 
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, 
      new Intent(this, NotificationsActivity.class), 0); 
    notification.setLatestEventInfo(this, "My notification","Hello World!", pendingIntent); 
    notificationManager.notify(1, notification); 

활동 코드 :

당신이 수신기/서비스 내에서 startActivity 할 경우에
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(dialogLayout); 
} 
+1

NotificationActivity 클래스가 AndroidManifest.xml에 정의되어 있습니까? (AndroidManifest를 붙여 넣을 수 있습니까?) –

답변

0

, 당신이를 만들어야합니다 새 태스크를 시작하도록 알리는 플래그를 추가 한 후 활동을 시작하십시오.

이 의사 코드를 적용 :

Intent startServiceIntent = new Intent(context, com.myCorp.myApp.myClass.class); 
startServiceIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
context.startActivity(startServiceIntent); 

내가 응용 프로그램 (for example use this BootReceiver를) 시작하는 BootReceiver이를 사용합니다.

관련 문제