我要实现以下情形:当用户按下Home键的通知显示在状态栏和应用程序通常隐藏方向变化和通知
。用户点击通知应用程序时通常会恢复。
这里是我的这段代码:
private int NOTIFICATION = R.string.local_service_started;
private NotificationManager mNM;
private void showNotification() {
CharSequence text = getText(R.string.local_service_started);
Notification notification = new Notification(R.drawable.icon, text, System.currentTimeMillis());
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, JingleCartoucheActivity.class), 0);
notification.setLatestEventInfo(this, getText(R.string.local_service_label), text, contentIntent);
mNM.notify(NOTIFICATION, notification);
}
@Override
public void onPause() {
super.onPause();
if (!isFinishing()) {
showNotification();
}
}
@Override
public void onResume() {
super.onResume();
mNM.cancel(NOTIFICATION);
}
所有这一切,除了一件事正常工作:
当应用程序被运行,用户旋转手机时,创建通知,立即销毁。有没有办法检测onPause()中的手机方向更改并且不显示此通知?