2016-04-06 32 views
0

我使用Android Studio。Android:啓動新活動時出現黑屏

我有一個活動電話NewGame其中包括一堆動畫。從NewGame我想開始另一個活動,名爲PetInfo,但由於某些原因,此活動未啓動。相反,出現黑屏,無論等待多久,它都不會消失。但是,當發生這種情況時,在Android監視器中,如果我點擊紅色的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" /> 

+0

請提供一些代碼 – Pooya

+0

添加代碼。謝謝! –

+0

你怎麼稱呼「createInfo」? – Pooya

回答

0
<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> 

這是將RelativeLayout的內部意見,你PetInfo佈局文件的正確方法。

+0

我改變了這個,但同樣的事情仍然發生......雖然謝謝! –

+0

嘗試在relativelayout上設置背景顏色,看看是否可以看到您設置的顏色,這樣您至少會知道佈局正在充氣。 – kimchibooty

+0

我明白了。對我來說問題是我有線程運行,我沒有停止線程,所以線程從未加入。感謝您的幫助! –

0

由於game_view.pause()在在NewGame Activity。可能是你的pause()在主線程中做了巨大的處理。