2
사용자가 알림을 클릭하면 어떻게 활동을 시작합니까? 나는 끊임없는 충돌을 겪고있다. 작동 알림을 클릭 할 수 없습니다. 아래에 onclick 메소드가 있습니다. ButtonOne 버튼이 눌려지면, 화면 상단의 메뉴 바에 알림이 시작됩니다. 알림을 눌러 MainActivity라는 액티비티를 시작할 수있게하고 싶었습니다. 충돌이 발생하고 페이지가 실행되지 않습니다. MainActivity 클래스 내부에 넣은 알림 코드에 문제가있을 수 있습니다. 뭐가 잘못 되었 니?알림을 클릭하여 활동을 시작하는 방법은 무엇입니까?
ButtonOne.setOnClickListener(new View.OnClickListener() {
private int mId;
// anonymous inner class override for on click
public void onClick(View v) {
Intent myIntent = new Intent(MainActivity.this, CoverFlowExample.class);
MainActivity.this.startActivity(myIntent);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(MainActivity.this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("My notification")
.setContentText("Hello World!");
// Creates an explicit intent for an Activity in your app
Intent resultIntent = new Intent(MainActivity.this, MainActivity.class);
// The stack builder object will contain an artificial back stack for the
// started Activity.
// This ensures that navigating backward from the Activity leads out of
// your application to the Home screen.
TaskStackBuilder stackBuilder = TaskStackBuilder.create(MainActivity.this);
// Adds the back stack for the Intent (but not the Intent itself)
stackBuilder.addParentStack(MainActivity.class);
// Adds the Intent that starts the Activity to the top of the stack
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent =
stackBuilder.getPendingIntent(
0,
PendingIntent.FLAG_UPDATE_CURRENT
);
mBuilder.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// mId allows you to update the notification later on.
mNotificationManager.notify(mId, mBuilder.build());
}
});