android - activity.finish() is not stopped current activity -
i have created android apps using async task call web service, when authentication fail, user stop current activity , redirect login page.
my problem when user redirect login page, toast text still showing, toast text under async thread onpostexceute() event.
any solution problem?
in webservice.cs
catch (unauthorizedexception ua) { log.d(tag, ua.getmessage()); intent intent = new intent(activity, loginactivity.class); if(condition a){ intent.putextra("toast_text", r.string.a); }else{ intent.putextra("toast_text", r.string.b); } activity.finish(); activity.startactivity(intent); } return null;
then in asynctask.cs
protected jsonarray doinbackground(string... parameters) { connectivitymanager cm = (connectivitymanager) singleformactivity.this.getsystemservice(context.connectivity_service); networkinfo activenetwork = cm.getactivenetworkinfo(); boolean isconnected = activenetwork != null && activenetwork.isconnectedorconnecting(); if (isconnected) { } return null; } public void onpostexecute(jsonarray result){ if(result != null){ }else{ toast.maketext(something.this, r.string.b, toast.length_long).show(); } }
you can use
create toast
toast toast = toast.maketext(getapplicationcontext(), "", toast.length_long);
and before calling finish()
cancel toast using below code
if (toast != null ) toast.cancel();
Comments
Post a Comment