Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is ConnectivityManager.getActiveNetworkInfo() expensive to call often?

I'm trying to figure out a strategy for my application, where I need to perform different network operations. My question is, whether calling ConnectivityManager.getActiveNetworkInfo() is considered a long-running and battery-draining operation and whether it's all right to call it often, or should I optimize my application's performance by applying another strategy? Thanks in advance.

like image 839
Egor Avatar asked Jan 24 '26 00:01

Egor


1 Answers

I have used ConnectivityManager.getActiveNetworkInfo() in three apps so far. You might use a checkNetwork() method and call it to ensure you are in the correct state each time the user starts something that needs the network so that he or she can correct the situation. Beyond that, your error-handling might combine sleep() calls with network checks and connection management. This means using about 30-gazillion permissions. But it would be a reasonable way to do it.

like image 168
R Earle Harris Avatar answered Jan 26 '26 16:01

R Earle Harris