【发布时间】:2013-12-05 16:52:23
【问题描述】:
我想为我的应用创建第二个活动,然后应用在每次切换到新活动时都会出现黑屏并崩溃。
禁用新活动时,该应用程序可以完美运行。我尝试了很多来修复它,但没有用。我可能错过了什么。
请注意,我创建了第二个活动 LAUNCHER 类别,并将第一个活动更改为 DEFAULT,并且模拟器在运行时不显示应用程序,它说它已安装但不会运行,并且不在虚拟移动菜单上。
这是第二个 Activity xml 文件:
<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"
tools:context=".MenuActivity" >
<TextView
android:id="@+id/WelcomeText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="41dp"
android:text="Welcome !"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="@+id/Play"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/WelcomeText"
android:layout_centerHorizontal="true"
android:layout_marginTop="48dp"
android:text="S t a r t G a m e" />
<Button
android:id="@+id/QuitMenu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="41dp"
android:text="Quit Game" />
</RelativeLayout>
这里是它的 Java 代码:
package com.example.write_example;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
public class MenuActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.menu);
Button start = (Button) findViewById(R.id.Play);
Button exit = (Button) findViewById(R.id.QuitMenu);
start.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity (newIntent("android.intent.action.MAIN"));
}
});
exit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
}
}
这是清单代码:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.write_example"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="1"
android:targetSdkVersion="17" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="MenuActivity"
android:label="@string/app_name" android:launchMode="standard">
<intent-filter>
<action android:name="android.intent.action.MainMenu" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
感谢您的帮助,感谢您的宝贵时间。
【问题讨论】:
-
可以添加你崩溃的logcat吗?
-
@gahfy 我很想添加它,但是当我选择“将日志保存到文本文件”时,它会在日志文本文件中给出一个长文本,并在这里吃掉整个页面
-
@SoulsReaper 您可以多选处理崩溃的行,然后单击保存,这样就只能在此处发布相关的堆栈跟踪
-
在 Eclipse 中,只需选择要共享的日志的第一行,然后按 shift 并选择最后一行。然后按Ctrl + C。粘贴到这里。
-
@gahfy 很抱歉这么说,但没有日志,因为应用程序在启动时运行第二个活动后永远不会运行
标签: android eclipse sdk android-activity android-manifest