ユーザーがクリックするとホーム画面に戻るボタンを追加していますが、ボタンをクリックするたびにアプリケーションが強制終了します。
2 に答える
1
私はあなたがNPEを取得していると思います。
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0); <<<<Error is here NPE
Intent intent = new Intent();
Intent intent=new Intent(Intent.ACTION_MAIN);
homeIntent.addCategory(Intent.CATEGORY_HOME); <<<There must be Compile time error because you did not declare homeIntent
homeIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(homeIntent);
于 2013-03-10T08:31:09.620 に答える
0
私が見る限り、あなたの問題はここにあると思います:
public void onClick(View v) {
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);
Notification noti = new Notification.Builder(this)
.setTicker("Ticker Title")
.setContentTitle("Content Title")
.setContentText("Notifcation Content")
.setSmallIcon(R.drawable.ic_launcher)
.setContentIntent(pIntent).getNotification();
noti.flags=Notification.FLAG_AUTO_CANCEL;
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(0, noti);
Intent intent = new Intent();
Intent intent=new Intent(Intent.ACTION_MAIN);
homeIntent.addCategory(Intent.CATEGORY_HOME);
homeIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(homeIntent);
}
この行の意図をより正確に:
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);
PendingIntent
実際に作成する前に、このインテントを に追加しようとしています。
そして、homeIntent
あなたは何を使用していますか?
于 2013-03-10T08:33:51.653 に答える