当我按回我的程序时,我得到一个空白屏幕

时间:2014-11-11 00:50:30

标签: java android

在进入chapter3_1.xml页面后,当我按下我的手机后退键时它会拉得很好,它会将我带到上一个按钮。再次按回来,那里有一个不应该在那里的空白页面。再次按回原点,然后进入原始按钮。没有错误没有崩溃。

清单

 <?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
 package="com.th3ramr0d.ar670_1quickreference"
 android:versionCode="1"
 android:versionName="1.0" >

 <uses-sdk
    android:minSdkVersion="14"
    android:targetSdkVersion="21" />

 <application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MainMenu"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>


    <activity
        android:name=".SubMenu1"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="com.th3ramr0d.ar670_1quickreference.SUBMENU1" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

    <activity
        android:name=".Chapter3"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="com.th3ramr0d.ar670_1quickreference.CHAPTER3" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

    <activity
        android:name=".Chapter3_1"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="com.th3ramr0d.ar670_1quickreference.CHAPTER3_1" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

 </application>

 </manifest>

MainMenu.java

 package com.th3ramr0d.ar670_1quickreference;

 import android.app.Activity;
 import android.content.Intent;
 import android.os.Bundle;
 import android.view.View;
 import android.widget.Button;

 public class MainMenu extends Activity{

 @Override
 protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Button btnChpt3 = (Button) findViewById(R.id.btnChpt3);
    btnChpt3.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            startActivity(new Intent("com.th3ramr0d.ar670_1quickreference.CHAPTER3"));
        }
    });
 }
 }

SubMenu1.java

 package com.th3ramr0d.ar670_1quickreference;

 import android.app.Activity;
 import android.content.Intent;
 import android.os.Bundle;
 import android.view.View;
 import android.widget.Button;

 public class SubMenu1 extends Activity{

 @Override
 protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.chapter3);

    Button btnChpt3 = (Button) findViewById(R.id.btnChpt3_1);
    btnChpt3.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            startActivity(new Intent("com.th3ramr0d.ar670_1quickreference.CHAPTER3_1"));
        }
    });
 }

 }

Chapter3.java

 package com.th3ramr0d.ar670_1quickreference;

 import android.app.Activity;
 import android.content.Intent;
 import android.os.Bundle;

 public class Chapter3 extends Activity{

 @Override
 protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    startActivity(new Intent("com.th3ramr0d.ar670_1quickreference.SUBMENU1"));
 }

 }

Chapter3_1.java

 package com.th3ramr0d.ar670_1quickreference;

 import android.app.Activity;
 import android.os.Bundle;

 public class Chapter3_1 extends Activity{

 @Override
 protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.chapter3_1);
 }
 }

activity_main.xml中

 <LinearLayout 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="com.th3ramr0d.ar670_1quickreference.MainActivity" >

 <Button
    android:id="@+id/btnChpt3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Chapter 3" />

 </LinearLayout>

chapter3.xml

  <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:orientation="vertical" >

 <Button
    android:id="@+id/btnChpt3_1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="fuckmylife" />

 </LinearLayout>

chapter3_1.xml

 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:orientation="vertical" >

 <TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="This is the content of chapter 3_1"
    android:textAppearance="?android:attr/textAppearanceLarge" />

 </LinearLayout>

2 个答案:

答案 0 :(得分:2)

我认为您在应用程序中使用片段。 当你推动片段时,你将它添加到后面的堆栈,这就是为什么当你按下后退按钮它会显示一个空白屏幕,这是你在显示片段视图的framelayout。 请参阅link :-

Fragmnet manager

答案 1 :(得分:1)

在你的清单中,你应该在活动中像这样设置父母:

  android:parentActivityName="com.some.myproject.ParentActivityToThisActivity"

但它无法使用API​​ 14,应该使用API​​ 15或最新版本。