2011-08-31 46 views
0

我的代碼是通知不能跳到另一個活動?

public class AlarmReceiver extends BroadcastReceiver { 
public Notification mNotification = null; 
public NotificationManager mNotificationManager = null; 

@Override 
public void onReceive(Context context, Intent intent) { 
    Toast.makeText(context, "time up!", Toast.LENGTH_SHORT).show(); 
    mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); 
    mNotification = new Notification(R.drawable.icon, "tip!", 
      System.currentTimeMillis()); 
    mNotification.contentView = new RemoteViews(context.getPackageName(), 
      R.layout.notification); 
    mNotification.contentView.setTextViewText(R.id.tv_tip, "click to see the description"); 
    Intent notificationIntent = new Intent(context,NotificationTip.class); 
    notificationIntent.putExtra("description", intent.getStringExtra("description")) ; 
    //notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, 
      notificationIntent, 0); 
    mNotification.contentIntent = contentIntent; 
    mNotificationManager.notify(0, mNotification); 
} 

}

雖然當我點擊通告的項目,我不能去NotificationTip活動,有什麼不對的代碼?

回答

0

以下行

Intent notificationIntent = new Intent(context,NotificationTip.class); 

需求是

Intent notificationIntent = new Intent("X"); 

其中,X爲意圖的動作名稱。這你必須添加爲您的Android清單文件中的intent過濾器。

+0

謝謝您提醒。 – user898366

+0

我忘記在清單文件中註冊。 – user898366

相關問題