0
我嘗試從新通知添加到數據庫(我正在使用Firebase數據庫)時更新的通知中啓動活動。無法從使用Firebase的通知中啓動特定活動
通知完美,但每當我試圖從通知啓動UserDashboardActivity。它不工作。
任何人都可以幫助我。
我的代碼:
這裏面服務
public class NotificationService extends Service {
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
notifyMe(order.amount);
return START_STICKY;
}
private void notifyMe(String amount){
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.add_order)
.setContentTitle("New Order")
.setContentText("Order amount: " + amount)
.setAutoCancel(true);
Intent notificationIntent = new Intent(this,UserDashboardActivity.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent contentIntent = PendingIntent.getActivity(this,0,notificationIntent,PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(contentIntent);
NotificationManager manager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
manager.notify(0,builder.build());
}
}
通知代碼時UserDoashboardActivity停止
@Override
protected void onStop() {
super.onStop();
Intent intent = new Intent(UserDashboardActivity.this, NotificationService.class);
startService(intent);
}
只是爲了說清楚 - 如果您將UserDashboardActivity替換爲任何其他活動,它是否有效? – SadClown
是的...... –
另外我開始從UserDashboardActivity的服務 –