In order to learn how to use the AlarmManager I created an activity
that consists of a single button. When the button is pressed the
activity creates an Intent of itself and loads it into the
AlarmManager 3 seconds in the future before finishing.
So activity opens, user pushes button, activity closes, 3 seconds
later activity opens, repeat.
Problem is instead of opening the activity 3 seconds later I get an
error: "The application [myappname] has stopped unexpectedly. Please
try
again." however I was able to open a Toast from the Receiver just
fine.
Here's the code for the button:
thanksButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
setResult(RESULT_OK);
Intent intent = new Intent(myappname.this,
myappnameBroadcastReceiver.class);
PendingIntent appIntent = PendingIntent.getBroadcast
(myappname.this, 0, intent, 0);
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.add(Calendar.SECOND, 3);
AlarmManager am = (AlarmManager)getSystemService
(ALARM_SERVICE);
am.set(AlarmManager.RTC, calendar.getTimeInMillis(),
appIntent);
finish();
}
});
--------------------------------------------
Here's the broadcast receiver:
package com.myappname;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class myappnameBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
context.startActivity(new Intent(context,
myappname.class));
}
}
---------------------------------------------
and here's the lines from the manifest.xml
<receiver
android:name=".myappnameBroadcastReceiver"
android:process=":remote">
</receiver>
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en