Android 未知空白活动?
我正在尝试打开存储在我的资产文件夹中的pdf文件。下面给出了我正在使用的代码。代码工作得很好,但是我面临的问题是当我按下PDF打开后的回退按钮,我进入空白屏幕,我必须再回去再一次到达从PDF启动的屏幕。有人能帮我吗。谢谢Android 未知空白活动?,android,android-layout,Android,Android Layout,我正在尝试打开存储在我的资产文件夹中的pdf文件。下面给出了我正在使用的代码。代码工作得很好,但是我面临的问题是当我按下PDF打开后的回退按钮,我进入空白屏幕,我必须再回去再一次到达从PDF启动的屏幕。有人能帮我吗。谢谢 public class SampleActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCrea
public class SampleActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
CopyReadAssets();
}
private void CopyReadAssets() {
AssetManager assetManager = getAssets();
InputStream in = null;
OutputStream out = null;
File file = new File(getFilesDir(), "git.pdf");
try {
in = assetManager.open("git.pdf");
out = openFileOutput(file.getName(), Context.MODE_WORLD_READABLE);
copyFile(in, out);
in.close();
in = null;
out.flush();
out.close();
out = null;
} catch (Exception e) {
Log.e("tag", e.getMessage());
}
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(
Uri.parse("file://" + getFilesDir() + "/git.pdf"),
"application/pdf");
startActivity(intent);
}
private void copyFile(InputStream in, OutputStream out) throws IOException {
byte[] buffer = new byte[1024];
int read;
while ((read = in.read(buffer)) != -1) {
out.write(buffer, 0, read);
}
}
}
好的,问题是您正在从另一个活动调用此活动-然后从这个活动调用另一个活动来实际显示PDF文件。当用户从PDF中按“后退”时,您将看到此活动;然后你再按一下“后退”键,结果就是原来的通话键 相反,不要创建第二个活动。将
copyreadset
和copyreadset
方法移动到您的第一个活动中,然后单击按钮(或任何触发器)调用您的copyreadset
方法
此活动不需要存在。是否从其他活动调用此活动?
R.layout.main
(即您的main.xml
layout)中有什么内容?@AleksG是的,我正在从另一个活动调用它。我尝试过删除setcontentview行,但仍然遇到同样的问题