android - App is crashed when I start Service after Boot -


i want start service when turn on device. if start activity, working fine in case of service crashed. please guide me. code here. in logcat. getting error activitynotfoundexception. how solve issue?

my screenshot of error when device turn on

my service

public class startserviceafterboot extends broadcastreceiver {  public startserviceafterboot() { }  @override public void onreceive(context context, intent intent) {     if (intent.getaction().equals(intent.action_boot_completed)) {         intent = new intent(context, backgroundlocationservice.class);         i.addflags(intent.flag_activity_new_task);         context.startactivity(i);     } } 

}

my activity

public class mainactivity extends appcompatactivity {  private button mstartupdatesbutton; private button mstopupdatesbutton;  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);     toolbar toolbar = (toolbar) findviewbyid(r.id.toolbar);     setsupportactionbar(toolbar);      intent intent = new intent(mainactivity.this, backgroundlocationservice.class);     startservice(intent); } 

my manifest

<service android:name=".locationupdates" />     <service android:name=".backgroundlocationservice" />     <receiver         android:enabled="true"         android:exported="true"         android:name="com.locationupdates.broadcast.startserviceafterboot"         android:permission="android.permission.receive_boot_completed">          <intent-filter>             <action android:name="android.intent.action.boot_completed" />             <action android:name="android.intent.action.quickboot_poweron" />             <category android:name="android.intent.category.default" />         </intent-filter>      </receiver> 

intent = new intent(context, backgroundlocationservice.class); i.addflags(intent.flag_activity_new_task); startservice(i); 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -