Fix for #511200 - run widget updater in the background. Also tweaked auto-synchronization in background. Hopefully that doesn't break :|

pull/14/head
Tim Su 16 years ago
parent 0857f9c1d3
commit e2f9d652aa

@ -375,9 +375,8 @@ Thanks for using Astrid!\n
It looks like you are using a task killer application! Please add Astrid to
the exclusion list for your task killer. Otherwise, if Astrid gets killed,
it will not let you know when your tasks are due.\n
\n
In other words: don\'t kill Astrid!
</string>
<string name="task_killer_help_ok">I Won\'t Kill Astrid!</string>
<!-- Locale Plugin -->
<skip />

@ -84,8 +84,8 @@ public class SynchronizationService extends BroadcastReceiver {
offset = Math.max(offset, AUTO_SYNC_MIN_OFFSET);
AlarmManager am = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0,
createAlarmIntent(context), 0);
PendingIntent pendingIntent = PendingIntent.getService(context, 0,
createAlarmIntent(context), PendingIntent.FLAG_UPDATE_CURRENT);
if (Constants.DEBUG)
Log.e("Astrid", "Autosync set for " + offset / 1000
@ -95,7 +95,7 @@ public class SynchronizationService extends BroadcastReceiver {
am.cancel(pendingIntent);
// schedule new
am.setInexactRepeating(AlarmManager.RTC, System.currentTimeMillis() + offset,
am.setInexactRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + offset,
interval, pendingIntent);
}
@ -105,8 +105,8 @@ public class SynchronizationService extends BroadcastReceiver {
*/
public static void unscheduleService(Context context) {
AlarmManager am = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0,
createAlarmIntent(context), 0);
PendingIntent pendingIntent = PendingIntent.getService(context, 0,
createAlarmIntent(context), PendingIntent.FLAG_UPDATE_CURRENT);
am.cancel(pendingIntent);
}

@ -13,7 +13,9 @@ public class Constants {
/** Flurry API KEy */
public static final String FLURRY_KEY = "T3JAY9TV2JFMJR4YTG16";
public static final boolean DEBUG = true;
public static final boolean DEBUG = false;
public static final long WIDGET_UPDATE_INTERVAL = 30 * 60 * 1000L;
// result codes

@ -3,6 +3,9 @@ package com.timsu.astrid.utilities;
import java.util.List;
import android.Manifest;
import android.app.AlarmManager;
import android.app.AlertDialog;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
@ -66,25 +69,30 @@ public class StartupReceiver extends BroadcastReceiver {
}
// schedule alarms in background every time Astrid is run
// perform startup activities in a background thread
new Thread(new Runnable() {
public void run() {
// schedule alarms
Notifications.scheduleAllAlarms(context);
// start widget updating alarm
AlarmManager am = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(context, UpdateService.class);
PendingIntent pendingIntent = PendingIntent.getService(context,
0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
am.setInexactRepeating(AlarmManager.RTC, 0,
Constants.WIDGET_UPDATE_INTERVAL, pendingIntent);
}
}).start();
Preferences.setPreferenceDefaults(context);
// start synchronization service
SynchronizationService.scheduleService(context);
// update widget
Intent intent = new Intent(context, UpdateService.class);
context.startService(intent);
// check for task killers
showTaskKillerHelp(context);
// start synchronization service
SynchronizationService.scheduleService(context);
hasStartedUp = true;
}
@ -93,31 +101,37 @@ public class StartupReceiver extends BroadcastReceiver {
return;
// search for task killers. if they exist, show the help!
new Thread(new Runnable() {
@Override
public void run() {
PackageManager pm = context.getPackageManager();
List<PackageInfo> apps = pm
.getInstalledPackages(PackageManager.GET_PERMISSIONS);
for (PackageInfo app : apps) {
outer: for (PackageInfo app : apps) {
if(app == null || app.requestedPermissions == null)
continue;
if(app.packageName.startsWith("com.android"))
continue;
for (String permission : app.requestedPermissions) {
if (Manifest.permission.RESTART_PACKAGES
.equals(permission)) {
DialogUtilities.okDialog(context, context
.getString(R.string.task_killer_help),
new OnClickListener() {
if (Manifest.permission.RESTART_PACKAGES.equals(permission)) {
Log.e("astrid", "found task killer: " + app.packageName);
OnClickListener listener = new OnClickListener() {
@Override
public void onClick(
DialogInterface arg0, int arg1) {
Preferences
.setShouldShowTaskKillerHelp(
public void onClick(DialogInterface arg0,
int arg1) {
Preferences.setShouldShowTaskKillerHelp(
context, true);
}
});
}
};
new AlertDialog.Builder(context)
.setTitle(R.string.information_title)
.setMessage(R.string.task_killer_help)
.setIcon(android.R.drawable.ic_dialog_alert)
.setPositiveButton(R.string.task_killer_help_ok, listener)
.show();
break outer;
}
}
}
}).start();
}
}

Loading…
Cancel
Save