Android Studio: a new action opens as a blank screen

Hello!
I am just starting out in Android Studio. I was looking for a suitable question, but without joy, please scream if you have already seen this!

In my main action, there is one button that opens the second action, the button works and opens. But the second action appears as a blank screen instead of the text that should be there.

Sorry for any irrelevant copy / paste!

manifest:

<application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:theme="@style/Theme.AppCompat.NoActionBar" > <activity android:name=".MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".fiveThreeOne" android:label="@string/title531"> </activity> </application> 

Primary activity:

 <RelativeLayout 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" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:textColor="#ffdedede" android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="fiveThreeOne" android:textAllCaps="false" android:id="@+id/open531btn" android:layout_below="@+id/mainTitle" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_marginTop="38dp" /> </RelativeLayout> 

Button code in the main class

 public class MainActivity extends ActionBarActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button open531button = (Button) findViewById(R.id.open531btn); open531button.setOnClickListener(new OnClickListener(){ public void onClick(View v){ startActivity(new Intent(MainActivity.this, fiveThreeOne.class)); } }); } 

Second xml activity

 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:text="@string/title531" android:layout_width="wrap_content" android:layout_height="wrap_content" android:editable="false" android:textSize="35sp" android:id="@+id/title531" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" /> </RelativeLayout> 

Thanks!

+7
java android android-activity android-studio
source share
3 answers

Have you set the layout for your activity in the setContentView () line as follows. Here activity_second is the action layout of my SecondActivity

 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_second); } 

if not, your activity will be displayed as empty. Hope this solves your problem.

+9
source share

It sometimes happens that instead of overloading

 protected void onCreate(Bundle savedInstanceState) { 

you finish the overload

 public void onCreate(@Nullable Bundle savedInstanceState, @Nullable PersistableBundle persistentState) 

instead of this. Make sure that onCreate with only the InstanceState stored as an argument is overloaded.

+30
source share

To check the weather, you set the correct layout for the setContentView () method of your second action.

0
source share

All Articles