check isOnline before getting data from internet if its true get the data
from internet if not redirect back to user.

On Tue, Oct 4, 2016 at 1:24 AM, Aaron D <alohaaa...@gmail.com> wrote:

> Hi, I want to test if my activity has online access.
> I click a button to execute an activity (downloads a list of people from a 
> database and populates it within the app) but I don't know where to put it?
>
> When online activity is not detected I want the user to get a popup dialog 
> box which says "No internet connectivity" and press OK.
>
> The app would return/stay at the same screen where the user pressed the 
> button to execute the activity.
>
> Where should I execute the isOnline code and how do I get the behavior I 
> want?  In the background task?
>
> Thanks!
>
> #code from google search stack overflow
> private boolean isOnline()
>     {
>         try
>         {
>             ConnectivityManager cm = 
> (ConnectivityManager)mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
>             return cm.getActiveNetworkInfo().isConnectedOrConnecting();
>         }
>         catch (Exception e)
>         {
>             return false;
>         }
>     }
>
> --
> You received this message because you are subscribed to the Google Groups
> "Android Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to android-developers+unsubscr...@googlegroups.com.
> To post to this group, send email to android-developers@googlegroups.com.
> Visit this group at https://groups.google.com/group/android-developers.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/android-developers/461d44a1-937b-4e93-8d2f-
> a699e5d8fc1c%40googlegroups.com
> <https://groups.google.com/d/msgid/android-developers/461d44a1-937b-4e93-8d2f-a699e5d8fc1c%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to android-developers+unsubscr...@googlegroups.com.
To post to this group, send email to android-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/android-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/android-developers/CABHzXARDmcqH--R9K1DQVeg6aKHhUcOCm6_k8B1pOuXTBSeaLg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to