'Fragment keeps crashing when Bundle is in use
The webFragment.xml keeps crashing when i tried to use a url that provided from MenuFragment.xml. i tried the below methods but no luck. here is the MenuFragment code
MenuFragment.xml
Bundle bundle = new Bundle();
String url = "http://www.google.com"
bundle.putString("webUrl", url);
WebsFragment websFragment = new WebsFragment();
websFragment.setArguments(bundle);
getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.mainView, websFragment).commit();
WebFragment.xml
Bundle bundle = this.getArguments();
siteUrl = bundle.getString("webUrl");
//activity_main.xml
<androidx.fragment.app.FragmentTabHost
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TabWidget
android:id="@android:id/tabs"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"/>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0"/>
<FrameLayout
android:id="@+id/mainView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
</LinearLayout>
</androidx.fragment.app.FragmentTabHost>
//activity_web.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".WebsFragment">
<WebView
android:id="@+id/web_view"
android:layout_width="match_parent"
android:layout_height="match_parent">
</WebView>
</FrameLayout>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
