[英]Android: Black screen when starting a new activity
我使用Android Studio。
我有一個活動呼叫NewGame
,其中包含一堆動畫。 我想從NewGame
開始另一個名為PetInfo
活動,但是由於某些原因,該活動沒有開始。 相反,出現黑屏,無論我等待多長時間,黑屏都不會消失。 但是,發生這種情況時,如果我在Android Monitor中單擊紅色的X(終止應用程序),則黑屏消失,我的PetInfo
活動出現。
所以我不知道黑屏怎么辦。 不確定是否是因為NewGame
活動包含太多內容?
任何想法? 謝謝!
編輯:添加一些代碼
NewGame
活動
public class NewGame extends Activity {
GameView game_view;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
game_view = new GameView(this);
setContentView(R.layout.activity_new_game);
}
// This method executes when the player starts the game
@Override
protected void onResume() {
super.onResume();
// Tell the gameView resume method to execute
game_view.resume();
}
// This method executes when the player quits the game
@Override
protected void onPause() {
super.onPause();
// Tell the gameView pause method to execute
game_view.pause();
}
// Start new activity
public void createInfo(View view) {
Intent intent = new Intent(this, PetInfo.class);
startActivity(intent);
}
}
activity_new_game.xml
<?xml version="1.0" encoding="utf-8"?>
<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" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:text="OK"
android:onClick="createInfo"/>
</RelativeLayout>
PetInfo
活動
public class PetInfo extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
Log.d("test", "onCreate");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pet_info);
}
}
和activity_pet_info.xml
<?xml version="1.0" encoding="utf-8"?>
<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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:text="Pet Name"
android:ems="10"
android:id="@+id/pet_name"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="70dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:id="@+id/pet_birth"
android:layout_below="@+id/pet_name"
android:layout_centerHorizontal="true"
android:layout_marginTop="70dp" />
<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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"/>
<!-- views that will live in the relative layout -->
</RelativeLayout>
這是將視圖放置在PetInfo布局文件中的RelativeLayout內部的正確方法。
由於NewGame Activity
中onPause
中的game_view.pause()
。 可能是您的pause()
在主線程中進行了巨大的處理。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.