网上看到AlertDialog,今天在Laucher项目中用到了.
new AlertDialog.Builder(context)
.setTitle("行车记录仪")
.setMessage("是否打开")
.setPositiveButton("是", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
gotoApp(CAMERA_PACKET,CAMERA_CLASSNAME);
}
})
.setNegativeButton("否", null)
.show();
gotoApp()根据包名和类名打开一个应用
private void gotoApp(String packetName,String className){
try {
sendMsg(Contacts.HEX_OTHER_MODEL);
Intent intent = new Intent();
intent.setClassName(packetName, className);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
} catch (Exception e) {
e.printStackTrace();
}
}
本文介绍如何在Laucher项目中利用AlertDialog实现应用的切换操作,包括设置标题、消息、确认和取消按钮,并通过gotoApp()函数根据应用的包名和类名来启动目标应用。
1万+

被折叠的 条评论
为什么被折叠?



