[英]How to back second activity to first activity if no internet connection/wifi/mobile data (JAVA_CODE)
I am beginner android developer... Recently I develop an apps.我是初学者 android 开发人员...最近我开发了一个应用程序。 But I want If user device connected with wifi/mobile network and user open my apps automatically FirstActivity go to SecondActivity.
但我想如果用户设备连接到 wifi/移动网络并且用户自动打开我的应用程序 FirstActivity go 到 SecondActivity。 In SecondActivity user can read a pdfBook/html/txt file.
在 SecondActivity 中,用户可以阅读 pdfBook/html/txt 文件。 But when user Reading Pdfbook/html/txt file in SecondActivity and at the same time wifi/mobile network DISCONNECTED then SecondActivity automatically should come_back to FirstActivity.
但是当用户在 SecondActivity 中读取 Pdfbook/html/txt 文件并且同时 wifi/移动网络 DISCONNECTED 时,SecondActivity 应该自动返回到 FirstActivity。 I try many way, but I fail to do that.... there is no resource in GoogleSearch for this problem.
我尝试了很多方法,但我没有做到这一点.... GoogleSearch 中没有针对此问题的资源。 Please anybody help me.
请任何人帮助我。
public boolean isNetworkConnected(Context context) {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
return cm.getActiveNetworkInfo() != null && cm.getActiveNetworkInfo().isConnected();
}
this is the function that will return true if the network is connected这是 function 如果网络已连接将返回 true
and return false if the network is not connected如果网络未连接,则返回 false
if this function return true you go to next activty如果这个 function 返回真你 go 到下一个活动
if return false then what you want can do如果返回 false 那么你想要做什么
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.