2011-05-14 8 views
4

내 앱에서 안드로이드에 이상한 문제가 있습니다. 알림을 완료했으며 알림을 클릭하면 새로운 활동을 시작하려고합니다. 문제는 알림을 클릭해도 아무 일도 일어나지 않고 문제가 어디인지 전혀 알지 못한다는 것입니다. ? 의견에서와 같이알림을 클릭 할 때 활동을 시작하는 방법은 무엇입니까?

notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
CharSequence NotificationTicket = "Notification"; 
CharSequence NotificationTitle = "Notification"; 
CharSequence NotificationContent = "Test"; 
long when = System.currentTimeMillis(); 

Notification notification = new Notification(R.drawable.icon, 
NotificationTicket, when); 

Context context = getApplicationContext(); 

Intent notificationIntent = new Intent(this, ShopsOnMap.class); 
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, 
notificationIntent, 0); 

notification.setLatestEventInfo(context, NotificationTitle, NotificationContent, contentIntent); 
notificationManager.notify(NOTIFICATION_ID, notification); 
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP| Intent.FLAG_ACTIVITY_SINGLE_TOP); 
+0

팁 : 상단에 버튼이있는 막대는 코드를 쉽게 포맷 할 수있게 해줍니다 (예 : '{}'버튼 사용). – Nanne

+0

문제가 없는지, ShopsOnMap 활동의 oncreate에'Log.d' 디버깅 코드를 추가하여 문제가 있는지 확인할 수 있습니다. – Nanne

+0

당신이 말하고자하는 바를 이해할 수 없습니다. 좀 더 명확하게 표현할 수 있습니까? 아니면 LogCat에 – Gaby

답변

0

: 누군가가 나를 도울 수 여기에 나의 코드입니다 난 당신의 코드와 아무 잘못을 참조하고 shopsonmap 그냥 아무것도 보여주지 의심 할 수 없다. 아래 코드는 제가 사용하는 코드입니다.

+0

뭔가를 추가하겠습니다. 문제가 내 수업 인 ShopsOnMap이라는 것을 알았습니다. 나는 다른 반과 함께 노력했고 효과가있다. 하지만 지금은 새로운 문제가 있습니다.이 경우에 사용하기 위해 새 클래스를 만들면 NoClassDefFound 오류가 발생합니다 ... 솔루션에 대한 검색이 많이 있었지만 도움이되지 않았습니다. 이 오류에 대한 해결책을 알고 있습니까? – Gaby

+0

매니페스트에 넣었습니까? 어쩌면 이것을 응답으로 표시하고, 일부 코드 (클래스, 호출 및 매니 페스트)와 함께 다른 질문을 시작하십시오. – Nanne

9

나는 동일한 문제가 있었는데 그 때 내가 매니페스트에서 나의 새로운 활동을 선언하지 않았다는 것을 깨달았습니다.

2

이제이 질문은 매우 오래된 것으로 알고 있지만 해결책은 requestCode를 변경하는 것이 었습니다. 분명히 때로는 requestCode 0 때 가끔 작동하지 않습니다. 그것은 나를 위해 하나의 전화에서 작동하지만 다른에서 작동하지 않았다.

+1

고마워요! 그건 내 문제를 해결. – Trees

3

의도에 대한 작업 및 카테고리를 설정해야합니다.

이 활동은 응용 프로그램의 엔트리 포인트가 아닌 경우 :

Intent notificationIntent = new Intent(context, ShopsOnMap.class); 
notificationIntent.setAction(Intent.ACTION_MAIN); 
notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER); 
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 

PendingIntent myIntent = PendingIntent.getActivity(context, 0,notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); 

가 및 응용 프로그램의 진입 점 인 경우, 당신이 그것을처럼, XML로 그것을 가지고 :

<activity 
     android:name=".ShopsOnMap" 
     android:theme="@android:style/Theme.NoTitleBar" 
     android:windowSoftInputMode="adjustResize" 
      android:configChanges="orientation" 
     android:screenOrientation="portrait" 
     > 
     <intent-filter> 
      <category android:name="android.intent.category.LAUNCHER" /> 

      <action android:name="android.intent.action.MAIN" /> 
     </intent-filter> 
</activity> 

그래서, 그것을 추가하기 만하면됩니다 :

Intent notificationIntent = new Intent(context, ShopsOnMap.class); 
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 

PendingIntent myIntent = PendingIntent.getActivity(context, 0,notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); 

그것은 나를 위해 일합니다.

관련 문제