Hi ,
trying to develope an application for scheduling the task using the
AlarmManager.
but getting an error "The method getActivity() is undefined for the
type TestBroadcastActivity"
My class is:-
public class TestBroadcastActivity extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
try
{
Bundle bundle = intent.getExtras();
String message = bundle.getString("alarm_message");
Intent newIntent = new Intent(context,
TestBroadcastActivity.class);
newIntent.putExtra("alarm_message", message);
newIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(newIntent);
}
catch (Exception e)
{
e.printStackTrace();
}
}
private void setRecurringAlarm(Context context)
{
try
{
Calendar updateTime = Calendar.getInstance();
updateTime.setTimeZone(TimeZone.getTimeZone("GMT"));
updateTime.set(Calendar.HOUR_OF_DAY, 11);
updateTime.set(Calendar.MINUTE, 45);
Intent downloader = new Intent(context,
TestBroadcastActivity.class);
PendingIntent recurringDownload =
PendingIntent.getBroadcast(context,0, downloader,
PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager alarms =
(AlarmManager)getActivity().getSystemService(context.ALARM_SERVICE);
alarms.setInexactRepeating(AlarmManager.RTC_WAKEUP,updateTime.getTimeInMillis(),AlarmManager.INTERVAL_DAY,
recurringDownload);
}
catch (Exception e)
{
System.out.println("Exception---------->>"+e);
}
}
}
I have imported all the related packages, but unable to fix the error.
Please help me,
Thanks
--
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