I am trying to send data to my parse SDK Database using Alarm Manager.
I am able to send data without Alarm manager.
My below code is not working correctly as parse sdk database is not showing updated data.
Here is my code:
Main Activity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.create_todo);
setTitle(R.string.create_todo);
alarmMgr = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(this, AlarmReceiver.class);
alarmIntent = PendingIntent.getBroadcast(this, 0, intent, 0);
alarmMgr.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
AlarmManager.INTERVAL_FIFTEEN_MINUTES,
AlarmManager.INTERVAL_FIFTEEN_MINUTES, alarmIntent);
}
AlarmReceiver.java
public class AlarmReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
MyAsyncTask asyncTask = new MyAsyncTask();
asyncTask.execute(new String[]{});
}
class MyAsyncTask extends AsyncTask<String,Void,String>
{
@Override
protected String doInBackground(String... params) {
try {
ParseObject parseObject = new ParseObject("Todo");
parseObject.put("name", "abc");
parseObject.save();
}
catch(ParseException e)
{
}
return null;
}
}
}
Register your broadcast in AndroidManifest.xml file
Try below code:
alarm.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + AlarmManager.INTERVAL_FIFTEEN_MINUTES , AlarmManager.INTERVAL_FIFTEEN_MINUTES, pIntent);
From above code, Below things will be happened.
first time Broadcast will be fired after 15 min. then it will be fired every 15 min.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With