I’m creating an app for Android, and it is not listed in the market, so I made my own updater.
An Asynctask runs in the background checking for a new version. When there is a new version it creates a notification.
When the notification is in the status bar, opening the status bar is slow (and sometimes clicking on the notification won’t work).
Here is my code:
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);
}
This is in the main activity and gets called from the asynctask.
if (Integer.parseInt(xmlroosters.getVersionCode()) > currentversion) {
new Main().makensNotification(Update.class,
"The app needs an update.",
"Update",
"Click here to update the app.",
R.drawable.app);
}
Why is this slow? (Sometimes I can’t even open the status bar) and why sometimes clicking on it isn’t even possible?
I suspect you’re calling that over and over in a loop. You’re consuming all your phone’s available CPU cycles checking for an update 😉
Consider checking on a schedule …