有两个活动。以下是第一个活动。
@Override
public void onCreate(Bundle savedInstanceState) {
try {
super.onCreate(savedInstanceState);
final CharSequence[] items = {"Pick from gallery", "Shoot now"};
//Prepare the list dialog box
AlertDialog.Builder builder = new AlertDialog.Builder(this);
//Set its title
builder.setTitle("Choose a video");
//Set the list items along with checkbox and assign with the click listener
builder.setSingleChoiceItems(items, 0, new DialogInterface.OnClickListener() {
// Click listener
public void onClick(DialogInterface dialog, int item) {
if(items[item]=="Pick from gallery"){
Toast.makeText(getApplicationContext(), "Choose a video", Toast.LENGTH_SHORT).show();
dialog.dismiss();
Intent r1= new Intent("com.asin.amit.PIC");
r1.putExtra("choice", 1);
startActivity(r1);
}
if(items[item]=="Shoot now"){
Toast.makeText(getApplicationContext(), "Record a video", Toast.LENGTH_SHORT).show();
dialog.dismiss();
Intent r1= new Intent("com.asin.amit.PIC");
r1.putExtra("choice", 2);
startActivity(r1);
}
}
});
AlertDialog alert = builder.create();
//display dialog box
alert.show();
}
catch(Exception e)
{
Toast.makeText(getApplicationContext(), "Unknown issue, Kindly restart the application", Toast.LENGTH_LONG).show();
e.printStackTrace();
}
当用户处于第二个活动并按下 BACK 按钮时,我希望第一个活动开始,但现在只出现黑屏,弹出菜单不可见。我必须旋转手机才能获得菜单。如何使其默认?另外,是否try
需要使用super.onCreate
?
编辑
另一个问题是,在第二个活动中我没有做任何任务,第一个任务是从画廊中挑选一个视频。如果BACK
在这个阶段按下,然后出现一个空白屏幕,我必须BACK
再次按下。如何避免这种情况?