2013-02-09 38 views
0

我正在爲Android創建一個應用程序,它沒有在市場上列出,所以我創建了自己的更新程序。發出通知很慢?

一個的AsyncTask在後臺運行,檢查是否有新版本, 當有它創建了一個通知

當通知是在狀態欄,打開狀態欄是緩慢的(有時點擊一個新版本?在通知不會工作)

這裏是我的代碼:

public static void makeNotification(Class<?> newclass, CharSequence msg, CharSequence from, CharSequence message, int icon, Context c) { 
    PendingIntent newintent = PendingIntent.getActivity(c, 0, new Intent(c, newclass), 0); 
    NotificationManager nm = (NotificationManager) c.getSystemService(NOTIFICATION_SERVICE); 
    Notification notif = new Notification(icon, msg, System.currentTimeMillis()); 
    notif.setLatestEventInfo(c, from, message, newintent); 

    nm.notify(0, notif); 
} 

這是主要活動,並得到來自所謂的AsyncTask。

if (Integer.parseInt(xmlroosters.getVersionCode()) > currentversion){ 
       new Main().makensNotification(Update.class, "The app need an update.", "Update", "Click here to update the app.", R.drawable.app); 
      } 

有人能告訴我爲什麼這很慢嗎? (有時我甚至不能打開狀態欄) 以及爲什麼有時點擊它甚至不可能?

回答

1

我懷疑你是一遍又一遍的循環調用它。你就吃下所有手機的可用的CPU週期檢查更新;)

考慮檢查的時間表...

new CountDownTimer(1000, 1000) { 

    public void onTick(long millisUntilFinished) { 
     mTextField.setText("seconds remaining: " + millisUntilFinished/1000); 
    } 

    public void onFinish() { 
     mTextField.setText("done!"); 
    } 
    }.start(); 
+0

請問一個運行的AsyncTask不止一次? – WHDeveloper 2013-02-09 13:07:25

+0

通知的代碼在if循環中 - >檢查已編輯的問題 – WHDeveloper 2013-02-09 13:08:56

+0

不,但它是如何坐在那裏等待更新的? AsyncTask()包含一個循環,用於觀察更新? – 2013-02-09 13:11:22