2014-10-19 77 views
1

我几乎完成了我的应用程序开发,并且如果没有互联网连接,我甚至允许显示敬酒信息的方式。如果在没有互联网连接的情况下显示对话框,我需要知道如何关闭应用程序?如何在显示对话框后关闭应用程序?

  • 我的应用程序是一个web视图应用程序。所以当用户打开应用程序时,应用程序必须检查互联网连接。并显示对话框,如果没有网络和应用程序必须关闭后显示对话框。

OR

  • 我不希望用户看到“网页不可用”的页面,所以如果没有互联网连接,应用程序必须显示一个按钮“对话框后关闭关'。或者有什么方法可以将用户重定向到目录中的文本,该目录不显示互联网连接?

我只需要这些代码;所有其他代码已完成并正在正常工作。

回答

1

呼叫您的活动finish()方法一旦用户点击对话

+1

给予更多的内容和代码,并解释为什么这可能是一个解决方案 – 2014-10-19 12:10:15

2

只需调用完成()在对话框的onclick()函数破坏活动。像:

... 
builder.setMessage('There is no connection!! Please close the activity!') 
       .setPositiveButton('close', new DialogInterface.OnClickListener() { 
        public void onClick(DialogInterface dialog, int id) { 
         finish(); 
        } 
       }) 
... 
2

您可以检查互联网连接后,弹出一个对话框,如下

new AlertDialog.Builder(this) 
    .setTitle("Connection Error") 
    .setMessage("You are not connected to Internet.") 
    .setPositiveButton("Close", new DialogInterface.OnClickListener() { 
     public void onClick(DialogInterface dialog, int which) { 
      // finish the activity here or, 
      // redirect to another activity 
     } 
    }) 
    .show(); 
2

您可以设置视图的活动之前检查你的互联网连接。

像:

if(connnected){ 
    setContentView(layoutId); 
}else{ 
    show a tosat with information no internet; 
    finish activity. 
} 
+0

要由四个空格格式化代码/伪代码,缩进(或在编辑器中使用代码按钮)。 – halfer 2015-11-28 17:08:15

相关问题