How to restart service in android to call service oncreate again

前端 未结 6 1500
慢半拍i
慢半拍i 2020-12-09 08:10

I have a service in my Android Application which runs always.Now i have a settings from my server through GCM and update these settings to my service. I put my settings in o

6条回答
  •  有刺的猬
    2020-12-09 08:21

    The best solution is to use onDestroy().

    When need to restart the service just call

    RESTARTSERVICE = true;
    stopService(new Intent(this, CLASS_OF_SERVICE.class));
    

    and

    public void onDestroy()
    {
       if (RESTARTSERVICE)
        {
           startService(new Intent(this, CLASS_OF_SERVICE.class));
        }
    }
    

提交回复
热议问题