音楽の一時停止、アンドロイドのカスタム通知のボタンクリックで音楽を再生するなどのアクションを実行しようとしています。現在、私はこのようにやっています、
int icon = R.drawable.ic_launcher;
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, "Custom Notification", when);
NotificationManager mNotificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.layout);
contentView.setTextViewText(R.id.textView1, "Custom notification");
contentView.setOnClickPendingIntent(R.id.button1, pIntent);
notification.contentView = contentView;
Intent notificationIntent = new Intent(this, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.contentIntent = contentIntent;
notification.flags |= Notification.FLAG_NO_CLEAR; //Do not clear the notification
notification.defaults |= Notification.DEFAULT_LIGHTS; // LED
notification.defaults |= Notification.DEFAULT_VIBRATE; //Vibration
notification.defaults |= Notification.DEFAULT_SOUND; // Sound
mNotificationManager.notify(1, notification);
しかし、これは私を別の活動に連れて行きます。とにかく、同じアクティビティに通知アクションを実装することはありますか?
たとえば..通知を発生させ、ユーザーがそれを押すと、アクティビティに移動する代わりに、現在のアクティビティ/サービスで通常のメソッドを呼び出すとしましょう