Crowbarella
Lurker
I'm trying to schedule the running of a function in the MainActivity thread. I've tried both an AlarmManager and a Handler. They both look like they're going through, but nothing ever runs at the time it's supposed to. Not sure what I'm doing wrong here. Any help would be greatly appreciated. Admittedly, I'm a bit noobish, though this is my second app (both very basic).
The relevant sections of the code for Handler:
The relevant sections of the code for AlarmManager:
Then in MainActivity, there's a:
public TrainCheckerAlarm TCA = new TrainCheckerAlarm();
TCA.GetMA(this);
TCA.setAlarm(this,c1);
The relevant sections of the code for Handler:
Java:
public Runnable r;
public Handler TSH = new Handler();
@Override
protected void onCreate(Bundle savedInstanceState) {
...
r = new Runnable() {
@Override
public void run() { Log.d("Tag","Hi Again");
RefreshList();}
};
Calendar c1 = Calendar.getInstance();
c1.add(Calendar.MINUTE,1);
TSH.postAtTime(r, c1.getTimeInMillis());
The relevant sections of the code for AlarmManager:
Java:
public class TrainCheckerAlarm extends BroadcastReceiver {
public MainActivity ma;
public void GetMA(MainActivity m) {ma = m;}
@Override
public void onReceive(Context context, Intent intent)
{
ma.RefreshList();
}
public void setAlarm(Context context, Calendar cal)
{
AlarmManager am =( AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
Intent i = new Intent(context, TrainCheckerAlarm.class);
PendingIntent pi = PendingIntent.getBroadcast(context, 0, i, 0);
am.set(AlarmManager.ELAPSED_REALTIME, cal.getTimeInMillis(), pi);
}
}
public TrainCheckerAlarm TCA = new TrainCheckerAlarm();
TCA.GetMA(this);
TCA.setAlarm(this,c1);