android - ClasscastException in LauncherActivity -
i getting classcastexception when launching app problem in taxitwinapplication app = (taxitwinapplication)getapplication(); activity trying call method other class
public class launcheractivity extends activity {
@override public void oncreate(bundle icicle) { super.oncreate(icicle); intent intent; taxitwinapplication app = (taxitwinapplication)getapplication(); app.register(); switch (taxitwinapplication.getuserstate()) { case not_subscribed: case subscribed: intent = new intent(this, mainactivity.class); intent.addflags(flag_activity_new_task | flag_activity_clear_task); break; case participant: intent = new intent(this, mytaxitwinactivity.class); intent.addflags(flag_activity_new_task | flag_activity_clear_task); break; case owner: intent = new intent(this, mytaxitwinactivity.class); intent.addflags(flag_activity_new_task | flag_activity_clear_task); break; default: intent = new intent(this, mainactivity.class); intent.addflags(flag_activity_new_task | flag_activity_clear_task); } startactivity(intent); finish(); }
}
public class taxitwinapplication extends application {
private static int pendingnotificationscount = 0; private static userstate userstate = not_subscribed; private servicesmanagement servicesmanagement; private locationlistener locationlistener; @override public void oncreate() { super.oncreate(); } public void unregister() { locationmanager locationmanager = (locationmanager) getsystemservice(context.location_service); locationmanager.removeupdates(locationlistener); } public void register() { servicesmanagement = new servicesmanagement(this); locationlistener = new locationlistener() { public void onlocationchanged(location location) { locationupdate(location); } public void onstatuschanged(string provider, int status, bundle extras) { } public void onproviderenabled(string provider) { locationmanager locationmanager = (locationmanager) getsystemservice(context.location_service); if (activitycompat.checkselfpermission(getapplicationcontext(), manifest.permission.access_fine_location) != packagemanager.permission_granted && activitycompat.checkselfpermission(getapplicationcontext(), manifest.permission.access_coarse_location) != packagemanager.permission_granted) { // todo: consider calling // activitycompat#requestpermissions // here request missing permissions, , overriding // public void onrequestpermissionsresult(int requestcode, string[] permissions, // int[] grantresults) // handle case user grants permission. see documentation // activitycompat#requestpermissions more details. return; } locationmanager.requestlocationupdates(locationmanager.gps_provider, 10000, 3, this); } public void onproviderdisabled(string provider) { } }; //every 10 seconds , @ least 3 meters locationmanager locationmanager = (locationmanager) getsystemservice(context.location_service); locationmanager.requestlocationupdates(locationmanager.gps_provider, 10000, 3, locationlistener); } private void locationupdate(location location) { gcmhandler gcmhandler = new gcmhandler(this); gcmhandler.locationchanged(location); } public static int getpendingnotificationscount() { return pendingnotificationscount; } public static void setpendingnotificationscount(int pendingnotifications) { pendingnotificationscount = pendingnotifications; } public static userstate getuserstate() { return userstate; } public static void setuserstate(userstate userstate) { taxitwinapplication.userstate = userstate; } public static void exit(context context) { gcmhandler gcmhandler = new gcmhandler(context); if (userstate == userstate.owner || userstate == userstate.participant) { gcmhandler.leavetaxitwin(); } gcmhandler.unsubscribe(); taxitwinapplication app = (taxitwinapplication) context.getapplicationcontext(); app.unregister(); dbhelper dbhelper = new dbhelper(context); dbhelper.deletetables(dbhelper.getwritabledatabase()); android.os.process.killprocess(android.os.process.mypid()); }
}
<application android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:name="com....taxitwinapplication">
Comments
Post a Comment