2016-04-06 30 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()在主线程中做了巨大的处理。