简体   繁体   English

如果没有互联网连接/wifi/移动数据(JAVA_CODE),如何将第二个活动支持到第一个活动

[英]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.

相关问题 如何检查互联网连接(Wifi /移动数据)是否已启用? - How to check if the Internet connection (Wifi/Mobile data) is ENABLED? 如何将第一个Activity中的数据保存到第二个Activity中? - How to save the data in my ListView from the first Activity to the second Activity? 如何根据第一活动数据(单击单选按钮)从第二活动转到第三活动或第四活动? - How to go from second activity to third activity or fourth activity based on first activity data (Radio button clicked)? 显示有关第二个活动中设置的第一个活动的数据 - Displaying data on first activity that is set in the second activity 将数据从第二个活动移到第一个活动 - Move Data from Second Activity to first Activity 单击按钮从我的第二个活动返回到第一个活动后,整个数据都消失了 - after returning back from my second Activity to first Activity on clicking button the whole data is gone 第二项活动不会回到第一项 - Second activity won't go back to first 如何找到互联网连接类型是否通过java代码Wifi或LAN连接不与android - how to find the internet connection type whether Wifi or LAN connection through java code not with android 启动画面和第二项活动返回 - splashscreen and second activity back Android-如何从活动2返回活动1的第二个片段? - Android - How to back to the second fragment on Activity 1 from Activity 2?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM