I developed an android app which has a list view as its main gui, when the user click the item in the list, a webview will show basing on the content of the item.
It works fine, however when I clicked the back button in the android phone (or simulator), a blank white screen is shown, and the list view appears only after I click the back button again.
Can anyone help explain and help solve the problem?
Here is my WebviewActivity :
public class WebViewActivity extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.active_item_detail);
if (savedInstanceState == null) {
WebViewFragment wvf = new WebViewFragment();
Intent i = this.getIntent();
wvf.init(i.getExtras());
getFragmentManager().beginTransaction().add(R.id.webview, wvf).commit();
}
}
}
and WebviewFragment:
public class WebViewFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.active_item_detail, container, false);
WebView wv = (WebView) v.findViewById(R.id.webview);
wv.getSettings().setJavaScriptEnabled(true);
//data is the content
if(data!=null) {
wv.loadData(data, "text/html", "UTF-8");
}
return v;
}
}
The layout file is like:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical">
<WebView android:id="@+id/webview"
android:layout_height="match_parent"
android:layout_width="wrap_content"
tools:context="com.mycompany.myapp.WebViewFragment" />
</LinearLayout>