Android Button As WebView Click Link For Logout (or Delete SessionId)
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) {
String url = urls[0];
HttpClient httpclient = new DefaultHttpClient(getHttpParams());
HttpResponse response = null;
try {
switch (taskType) {
HttpGet httpget = new HttpGet(url);
response = httpclient.execute(httpget);
} catch (Exception e) {
Log.e(TAG, e.getLocalizedMessage(), e);
}
return response;
}
private HttpParams getHttpParams() {
HttpParams htpp = new BasicHttpParams();
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:
final ProgressDialog pd = new ProgressDialog(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)"