[英]dialog: switch activity in background
Can I start an activity in the background of a dialog? 我可以在对话框的后台开始活动吗?
What I would like: Activity starts dialog, dialog swaps activity shown in the background. 我想要的是:“活动启动对话框”,对话框交换后台显示的活动。 The dialog is not dismissed. 对话框未关闭。
I think this can only be done when Dialog is also an Activity. 我认为这只能在Dialog也是Activity时才能完成。
What I thought was a solution: 我认为是一种解决方案:
Problem: Act 2 will be shown in front of DialogActivity. 问题:Act 2将显示在DialogActivity的前面。 I want it to switch at the back. 我希望它在后面切换。
Is this possible? 这可能吗?
Follow these couple of points to have a working solution: 请遵循以下几点,以找到可行的解决方案:
Here is the sample code which demonstrates the working solution. 这是演示工作解决方案的示例代码。
// This is a button click handler.
public void launchDialog(final View v) {
// Create the dialog with application context
AlertDialog dialog = new AlertDialog.Builder(getApplicationContext())
.setTitle("Title")
.setMessage("This is dialog")
.create();
// Set the window type as system window
dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
dialog.show();
// Demonstrates the activity change behind the dialog.
v.postDelayed(new Runnable() {
@Override
public void run() {
Intent intent = new Intent(v.getContext(), MyActivity2.class);
startActivity(intent);
finish();
}
}, 3000);
}
Remember to set the permissions in manifest to use system windows: 切记在清单中设置权限以使用系统窗口:
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.