2016-04-06 14 views
0

私はAndroid Studioを使用しています。Android:新しいアクティビティを開始するときの黒い画面

アニメーションの束を含むアクティビティコール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" /> 

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

これはあなたのPetInfoレイアウトファイルにRelativeLayout内部ビューを配置する適切な方法です。

+0

これに変更しましたが、同じことがまだ起こっています...ありがとうございます! –

+0

relativelayoutに背景色を設定して、設定した色が見えるかどうかを確認してください。レイアウトが正しく膨張していることがわかります。 – kimchibooty

+0

私はそれを得た。私の問題は、スレッドを実行していて、スレッドが決して結合されないようにスレッドを停止しなかったことです。助けてくれてありがとう! –

0

game_view.pause()がでNewGame Activityであるため。あなたのpause()はメインスレッドで膨大な処理をしているかもしれません。

関連する問題