I want to post JSON string with HttpURLConnection api to the localhost server(WAMP) periodically every 60 seconds to be inserted in the database. Therefore, I am executing MyAs
first we create a service like this
public class ChatSevice extends IntentService{
public ChatSevice() {
super("Some");
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
// TODO Auto-generated method stub
//this is asynk task class
new ChatConnect(ChatSevice.this).execute();
return super.onStartCommand(intent, flags, startId);
}
@Override
protected void onHandleIntent(Intent intent) {
// TODO Auto-generated method stub
}
}
and now call this service like this way
Intent intent3 = new Intent(this, ChatSevice.class);
PendingIntent pintent3 = PendingIntent.getService(this, 0, intent3, 0);
AlarmManager alarm3 = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
// for 30 mint 60*60*1000
alarm3.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(),
1000, pintent3);
startService(new Intent(getBaseContext(), ChatSevice.class));