我有一个应用程序,到目前为止包含两个活动:
主菜单活动。
游戏活动
Main Menu Activity 包含一个使用以下代码启动 Game Activity 的按钮:
public void onClick(View clickedButton)
{
switch(clickedButton.getId())
{
case R.id.buttonPlay:
Intent i = new Intent("apple.banana.BouncingBallActivity");
startActivity(i);
break;
}
当用户完成游戏活动时,他按下后退按钮。这首先调用了 onPause() 方法,该方法暂停了游戏的动画线程。然后它调用 onStop() ,它在活动上调用 finish() 。用户返回到主菜单活动。代码概述如下:
public class BouncingBallActivity extends Activity{
private BouncingBallView bouncingBallView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
bouncingBallView = new BouncingBallView(this);
bouncingBallView.resume();
setContentView(bouncingBallView);
}
@Override
protected void onPause()
{
super.onPause();
bouncingBallView.pause();
}
@Override
protected void onResume()
{
super.onResume();
bouncingBallView.resume();
}
@Override
protected void onStop()
{
super.onStop();
this.finish();
}
}
问题是这仅在我从 Eclipse 启动应用程序时才有效。当我点击应用程序图标时,游戏从游戏活动开始。主菜单活动不出现。
我不清楚为什么会这样。这可能与清单有关。我在下面粘贴了相关部分:
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".BouncingBallActivity"
android:label="@string/app_name"
android:screenOrientation="landscape" >
<intent-filter>
<action android:name="apple.banana.BouncingBallActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".MainMenu"
android:label="@string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
我真的很感激这方面的任何帮助。谢谢。