java - Unable to start receiver (Activity Not Found) -
i developed application , put on app store. afterwords wanted change package name changed application id in build.gradle looks appropriate in link. didn't change else not package name, not manifest file etc. application worked fine it's showing error of activitynotfound exception on launcher activity called through broadcast receiver although activity defined in manifest file. may know wrong at? manifest file coding:
<receiver android:name=".powerconnectionreceiver"> <intent-filter> <action android:name="android.intent.action.action_power_connected" /> </intent-filter> </receiver> <activity android:name=".batterychargerfast" android:configchanges="orientation" android:screenorientation="portrait" android:label="@string/app_name" android:launchmode="singletask"> <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity>
and below coding of broadcast receiver:
public class powerconnectionreceiver extends broadcastreceiver { private string tag="powerconnectionreceiver"; @override public void onreceive(context context, intent intent) { intent = new intent(); i.setclassname("packagename", "packagename.batterychargerfast"); i.setflags(intent.flag_activity_new_task); i.putextra("fast", true); context.startactivity(i); } }
the error states:
java.lang.runtimeexception: unable start receiver packagename.powerconnectionreceiver: android.content.activitynotfoundexception: unable find explicit activity class {packagename/packagename.batterychargerfast}; have declared activity in androidmanifest.xml?
when change applicationid in gradle, overrides manifest's id. need change code from:
intent = new intent(); i.setclassname("packagename", "packagename.batterychargerfast");
to:
intent = new intent(); i.setclassname("your.new.app.id", "packagename.batterychargerfast");
or may simpler don't need consider this:
@override public void onreceive(context context, intent intent) { intent = new intent(context.getapplicationcontext(), batterychargerfast.class); i.setflags(intent.flag_activity_new_task); i.putextra("fast", true); context.startactivity(i); }
Comments
Post a Comment