Skip to content Skip to sidebar Skip to footer

Android Button As Webview Click Link For Logout (or Delete Sessionid)

In my WebView android, I want the user to logout on button click or any other way. I don't want to show any webpage after clicking that button. After that app should auto-exit(Syst

Solution 1:

Use Rest to make a get call to this URL.

To make it use an async task:

See an example here.

In your do in background do:

protected String doInBackground(String... urls) {
    Stringurl= urls[0];
    HttpClienthttpclient=newDefaultHttpClient(getHttpParams());
    HttpResponseresponse=null;
    try {
        switch (taskType) {
        HttpGethttpget=newHttpGet(url);
        response = httpclient.execute(httpget);  
    } catch (Exception e) {
        Log.e(TAG, e.getLocalizedMessage(), e);
    }
    return response;
}

private HttpParams getHttpParams() {

    HttpParamshtpp=newBasicHttpParams();

    HttpConnectionParams.setConnectionTimeout(htpp, CONN_TIMEOUT);
    HttpConnectionParams.setSoTimeout(htpp, SOCKET_TIMEOUT);

    return htpp;
}

Solution 2:

The main reason behind this question was this logout link has nothing to display. So I wanted something like click to logout. Simple Android button in Main Activity didn't help for this.

So, I created new blank activity, used same layout I was using, but instead of showing blank layout, I added ProcessDialog and made it non-cancel-able as follows:

finalProgressDialogpd=newProgressDialog(Logout.this);
    pd.setCancelable(false);
    pd.setCanceledOnTouchOutside(false);
    pd.setMessage("Please wait...");
    pd.show();

And in public void onPageFinished(WebView view, String url) method, I dismissed this ProcessDialog and fired an intent for login page of my app. Also overridden the public boolean shouldOverrideUrlLoading(WebView view, String url) to prevent it from going to out of app.

After that, simply webView.loadUrl(url);.

This way I fixed my problem. (If you know better and simpler way of doing it, please post.)

Post a Comment for "Android Button As Webview Click Link For Logout (or Delete Sessionid)"