gpt4 book ai didi

android - 黑屏错误

转载 作者:行者123 更新时间:2023-11-30 04:34:39 27 4
gpt4 key购买 nike

所以最近我设置了一个 Intent ,当一个按钮被点击时它会带来一个新的 Activity 。它工作正常但是当我去 Activity 然后尝试返回主屏幕时我得到一个黑屏。在黑屏上,如果我再回击一次,它会带我进入主菜单,但这很烦人。有什么想法吗?

播放按钮.java

package com.Dragon_Fruit;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;

public class playbutton extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);
Intent myIntent = new Intent(playbutton.this, PlayActivity.class);
playbutton.this.startActivity(myIntent);

}

}

PlayActivity.java

package com.Dragon_Fruit;

import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;

public class PlayActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);
setContentView(R.layout.playscreen);

}
}

list 中的 PlayActivity

<activity android:name=".PlayActivity"
android:label="@string/app_name"
android:screenOrientation="landscape"
android:configChanges="keyboard|keyboardHidden|orientation">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>

DragonFruitActivity.java

package com.Dragon_Fruit;

import java.io.IOException;

import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageButton;

public class DragonFruitActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

// ***BUTTON SOUND***//
final MediaPlayer buttonSound = MediaPlayer.create(
DragonFruitActivity.this, R.raw.button_click);

ImageButton playbutton = (ImageButton) findViewById(R.id.playbutton);
playbutton.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View arg0) {
arg0.setBackgroundResource(R.drawable.playbuttonselected);
// TODO Auto-generated method stub
if(buttonSound.isPlaying()) {
buttonSound.stop();
}

try {
buttonSound.prepare();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

buttonSound.start();

startActivity(new Intent(DragonFruitActivity.this,
playbutton.class));
}

});
ImageButton settingsbutton = (ImageButton) findViewById(R.id.settingsbutton);
settingsbutton.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
if(buttonSound.isPlaying()) {
buttonSound.stop();
}

try {
buttonSound.prepare();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

buttonSound.start();

startActivity(new Intent(DragonFruitActivity.this,
settingsbutton.class));
}

});
}
}

最佳答案

您的第一个 Activity 永远不会设置布局。在显示的代码中,您似乎正从 playbutton 转到 PlayActivity。当您在 PlayActivity 中按返回键时,它会返回到 playbutton。由于您从未在 playbutton 中的任何布局上调用过 setContentView(),它只是一个什么都不做的黑屏。看来您应该只删除 playbutton Activity 。

关于android - 黑屏错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7083992/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com