美好的一天,我一直有一個很難對付Android通知近來所以這裏是我的問題。我的應用程序所做的就是用戶登錄,如果成功,它將顯示主頁面。當用戶按下後退按鈕(從主頁面)時,它會最小化應用程序並創建通知,而不是返回到登錄頁面。我的問題是,當我按運行通知(從通知選項卡恢復應用程序)它會創建一個錯誤。 下面是我的一些代碼的Android強制關閉時,我想還原最小化通知
public class WelcomeActivity1 extends ListActivity{
private NotificationManager mNM;
Intent notificationIntent;
protected void onCreate(Bundle savedInstanceState) {
mNM = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
notificationIntent = new Intent(WelcomeActivity1.this, WelcomeActivity1.class);
}
public boolean onKeyDown(int keyCode, KeyEvent event){
if(keyCode == KeyEvent.KEYCODE_BACK){
showMinimized();
moveTaskToBack(true);
}
return super.onKeyDown(keyCode, event);
}
public void showMinimized(){
CharSequence text = "Zylun Intranet is Minimized";
Notification notification = new Notification(R.drawable.ic_launcher, text, System.currentTimeMillis());
PendingIntent contentIntent = PendingIntent.getActivity(WelcomeActivity1.this, 0, new Intent(this,WelcomeActivity1.class), 0);
notification.setLatestEventInfo(getApplicationContext(), "Zylun Intranet Main", "Running", contentIntent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//notification.flags = Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR;
mNM.notify(1,notification);
}
}
我會很感激,如果有人能告訴我什麼是錯我的代碼。謝謝!
當登錄憑據是正確的 http://i.imgur.com/0WROj.jpg?1
減少應用程序時,用戶會按後退按鈕(從主網頁) http://i.imgur.com/31yNl.jpg?1
這裏是我的錯誤:
10-29 07:45:01.196: E/AndroidRuntime(733): FATAL EXCEPTION: main
10-29 07:45:01.196: E/AndroidRuntime(733): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.app.intranetzylun1/com.app.intranetzylun1.WelcomeActivity1}: java.lang.NullPointerException
10-29 07:45:01.196: E/AndroidRuntime(733): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
10-29 07:45:01.196: E/AndroidRuntime(733): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
10-29 07:45:01.196: E/AndroidRuntime(733): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
10-29 07:45:01.196: E/AndroidRuntime(733): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
10-29 07:45:01.196: E/AndroidRuntime(733): at android.os.Handler.dispatchMessage(Handler.java:99)
10-29 07:45:01.196: E/AndroidRuntime(733): at android.os.Looper.loop(Looper.java:123)
10-29 07:45:01.196: E/AndroidRuntime(733): at android.app.ActivityThread.main(ActivityThread.java:4627)
10-29 07:45:01.196: E/AndroidRuntime(733): at java.lang.reflect.Method.invokeNative(Native Method)
10-29 07:45:01.196: E/AndroidRuntime(733): at java.lang.reflect.Method.invoke(Method.java:521)
10-29 07:45:01.196: E/AndroidRuntime(733): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
10-29 07:45:01.196: E/AndroidRuntime(733): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
10-29 07:45:01.196: E/AndroidRuntime(733): at dalvik.system.NativeStart.main(Native Method)
10-29 07:45:01.196: E/AndroidRuntime(733): Caused by: java.lang.NullPointerException
10-29 07:45:01.196: E/AndroidRuntime(733): at com.app.intranetzylun1.WelcomeActivity1.onCreate(WelcomeActivity1.java:105)
10-29 07:45:01.196: E/AndroidRuntime(733): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
10-29 07:45:01.196: E/AndroidRuntime(733): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
在'WelcomeActivity1.onCreate()'(第105行),你會得到一個'NullPointerException'。檢查你在那裏。 –
感謝您的回覆,我會在明天早上在辦公室檢查我的代碼,並儘快爲您更新。謝謝! – tucker