【发布时间】:2015-06-29 02:22:40
【问题描述】:
我有一个显示数据的活动,在一切开始之前,我会检查是否有互联网。如果没有,我将用户发送到 Wifi 设置。
我面临的问题是,在用户连接到互联网并按下后,应用程序是空的,没有数据。有没有办法重新加载此活动或重新创建它?
我尝试了这段代码,但它在我进入设置之前重新创建了活动,因此对话框保持打开状态
@Override
protected void onResume() {
super.onResume();
this.onCreate(null);
}
这是检查互联网连接的代码
if(!isNetworkAvailable()){
//Toast.makeText(getApplicationContext(), "internet is not avialable", Toast.LENGTH_LONG).show();
AlertDialog.Builder ad = new AlertDialog.Builder(this);
ad.setMessage("There is no Internet Connection.\n Please check your settings.");
ad.setCancelable(false);
ad.setPositiveButton("Internet Settings", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which)
{
startActivity(new Intent(android.provider.Settings.ACTION_WIFI_SETTINGS));
}
});
ad.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which)
{
finish();
}
});
ad.show();
}
【问题讨论】:
标签: android android-activity settings reload