Android: AsyncTask with AlarmManager and Service

后端 未结 3 953
清酒与你
清酒与你 2021-01-23 18:55

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

3条回答
  •  遇见更好的自我
    2021-01-23 19:41

    You can create Service for your purpose and for every 60 seconds, you need not use Alarm Manager. Because Service is providing intent filter functionality to call service after every Minute.

    for that you have to write following code when you will register your service:

    ServiceDemo serviceDemo = new ServiceDemo();
            IntentFilter s_intentFilter = new IntentFilter();
            s_intentFilter.addAction(Intent.ACTION_TIME_TICK);
            s_intentFilter.addAction(Intent.ACTION_TIME_CHANGED);
    
            registerReceiver(serviceDemo , s_intentFilter);
    

    Service will execute after every 60 seconds using this code.

提交回复
热议问题