Android, trying to save data from a class inherted from BroadcastReceiver
I’m using the AlarmManager to go offever that goes off every day to send off alarms. As it sets off an alarm, it sets a flag saying bthat alarm has gone off. I was going to save these flags in a file. I tries to use the method openFileOutput, but got a error, I’ assuming its because the class broadcastRecever DOES NOT HAVE That method. The flags are stored in a static class so the app can access them开发者_如何转开发 to. While the is running will the memory always be there? Must I save the state some how?
You can use openFileOutput
: call it on the Context passed to the broadcast receiver:
@Override
public void onReceive(Context context, Intent intent)
{
context.openFileOutput(....);
}
See http://developer.android.com/reference/android/content/Context.html#openFileOutput%28java.lang.String,%20int%29 for more detail.
精彩评论