android - How to run a service in 4.0? -


hi have developed service application using activity , works great in 2.2 , 2.3 android version , starts on boot , runs app once in 30 mins , sending location server in 4.0 app not running on services on boot can me why?

my code:

broadcastreceiver.java:

public class autostart extends broadcastreceiver {     public void onreceive(context arg0, intent arg1) {         if ("android.intent.action.boot_completed".equals(arg1.getaction())) {             intent intent = new intent(arg0, gps_back_process.class);             arg0.startservice(intent);             log.i("autostart", "started");         }     } } 

service.java:

public class gps_back_process extends service {     private static final string tag = "myservice";     @override     public void oncreate() {         // todo auto-generated method stub         super.oncreate();         log.d("testing", "service got created");         toast.maketext(this, "gps_back_process,oncreate();", toast.length_long).show();     }      @override     public ibinder onbind(intent arg0) {         // todo auto-generated method stub         return null;     }      @override     public void ondestroy() {         // todo auto-generated method stub         super.ondestroy();     }       @override     public void onstart(intent intent, int startid)     {         intent intents = new intent(getbasecontext(),mainactivity.class);         intents.setflags(intent.flag_activity_new_task);         startactivity(intents);         toast.maketext(this, "gps_back_process.oncreate();", toast.length_long).show();         log.d(tag, "onstart");     } } 

manifest:

    <uses-permission android:name="android.permission.receive_boot_completed" />         <uses-permission android:name="android.permission.broadcast_sticky" />      <receiver android:name=".autostart" >                 <intent-filter>                     <action android:name="android.intent.action.boot_completed" />                 </intent-filter>             </receiver> <activity android:name=".mainactivity" >         </activity>          <service             android:name=".gps_back_process"             android:enabled="true" />     </application> 

thank you.

this happens because android 3.1+ service not run on boot unless start(launch) application atleast once after installation. so, when install application , restart device prior of launching applications mainactivity broadcastreceiver won't fired. have launch mainactivity once , restart device. works!

for reference can check question here.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -