【发布时间】:2014-03-31 22:21:35
【问题描述】:
如果连接被禁用,我想在更改 wifi 设置菜单时重新启动活动。 这是我的代码(onCreate 方法):
boolean status = ConnectionManager.getConnectivityStatusString(this);
if(status){
networkStatus.setText("SEI CONNESSO AD INTERNET !");
}else{
networkStatus.setText("connection not present");
FragmentManager fragmentManager = getSupportFragmentManager();
MsgAlertConnection newAlertConnection = new MsgAlertConnection();
newAlertConnection.show(fragmentManager, "Fragment");
}
这是显示对话框的代码:
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the Builder class for convenient dialog construction
// 1. Instantiate an AlertDialog.Builder with its constructor
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
// 2. Chain together various setter methods to set the dialog characteristics
builder.setTitle("Connection Error !")
.setMessage("Please check your Internet Connection for start the application.")
.setPositiveButton("Back to Settings", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Intent intent=new Intent();
intent.setComponent(new ComponentName("com.android.settings", "com.android.settings.WirelessSettings"));
startActivity(intent);
}
});
// Create the AlertDialog object and return it
return builder.create();
}
当用户将 wifi 网络更改为“开启”时,我如何重新启动或恢复应用程序以检查网络连接?
谢谢
【问题讨论】: