android - Starting activity from fragment button click (intent) throws blank screen -
i'm trying start activity button placed in fragment, when run app (in emulator , in real device) , press button, activity doesn't start , blank screen whithout navigation bar appears. i've read lot this, , common error people had didn't declare activity or weren't inflating correct layout. idea appreciated, because don't right now.
here code of manifest:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.isa.example" > <application android:allowbackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:theme="@style/apptheme" > <activity android:name=".mainactivity" android:label="@string/app_name" android:screenorientation="portrait" android:theme="@style/theme.custommaterial" > <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> <activity android:name=".newactivity" android:label="@string/app_name" android:screenorientation="portrait" android:theme="@style/theme.custommaterial" > <intent-filter> <action android:name="com.isa.example.newactivity" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> </application> </manifest>
here code fragment layout:
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/container" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" tools:context=".mainactivity"> <button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="start new activity"/> </relativelayout>
code fragment:
public class fragment1 extends fragment { @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); } } @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view view = inflater.inflate(r.layout.fragment_fragment1, container, false); button button = (button) view.findviewbyid(r.id.button); button.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { intent = new intent(getactivity(), newactivity.class); startactivity(i); } }); return view; } }
code new activity layout:
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:textappearance="?android:attr/textappearancelarge" android:text="this new activity" android:id="@+id/textview" android:layout_gravity="center_horizontal" /> </linearlayout>
and code new activity:
public class newactivity extends activity{ @override public void oncreate(bundle savedinstancestate, persistablebundle persistentstate) { super.oncreate(savedinstancestate, persistentstate); setcontentview(r.layout.newactivity_layout); } }
what minimum sdk version? version of oncreate introduced in 21: stackoverflow.com/a/29871359/1541763 remove persistablebundle persistentstate parameters
Comments
Post a Comment