I launch my TestWebView activity. After my web page is loaded, I put
the app in the background by pressing the Home key. Then I bring the
TestWebActivity back to the foreground. Unexpectedly, TestWebView's
onCreate() is called when I bring the activity to the foreground. But
onDestroy is never called. This same thing happens every time I
tested. It appears the old TestWebView was not completely killed so
there are possibly duplicate web clients running.
My code:
package com.cisco.test;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
public class TestWebView extends Activity {
private static final String LOG_TAG = "Cu";
private WebView appView;
@Override
public void onCreate(Bundle savedInstanceState) {
Log.i(LOG_TAG, "app created");
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags
(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
setContentView(R.layout.main);
appView = (WebView) findViewById(R.id.appView);
/* This changes the setWebChromeClient to log alerts to
LogCat! Important for Javascript Debugging */
appView.setWebChromeClient(new WebChromeClient());
appView.getSettings().setJavaScriptEnabled(true);
appView.getSettings().setJavaScriptCanOpenWindowsAutomatically
(true);
Log.i(LOG_TAG, "Web cache mode: " + appView.getSettings
().getCacheMode());
String urlStr = "http://www.mywebsite.com";
appView.loadUrl(urlStr);
}
@Override
protected void onResume() {
super.onResume();
}
@Override
protected void onPause() {
super.onPause();
}
@Override
protected void onDestroy() {
Log.i(LOG_TAG, "app destroyed!");
super.onDestroy();
}
}
I am writing an IM web client which uses cometd push and this issue
caused serious problem for me because all my javascript is reloaded
every time the app comes to the foreground.
How can I ensure that only one webview/webclient is running at any
given time? Thanks!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---