0

I have a class where I receive an event - a boolean variable in this case, using EventBus/Otto(for Fragment/Activity or something similar for posibility to subscribe in simple class) like:

  @Subscribe
             public void onSubscribeMyData(boolean myData) {

             if(myData){
             Log.d("LOG_TAG", "my received string is true");
                  }   

             else{
             Log.d("LOG_TAG", "my received string is false");
                  }    
              }

UPDATE My class contains only this method:

//check network

   public boolean isNetworkAvailable(Context context) {
        ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();

        String ip = "217.26.147.42";
        AsyncTaskIsOnline taskIsOnline = new AsyncTaskIsOnline();
        taskIsOnline.execute(ip);

        return networkInfo != null && networkInfo.isConnectedOrConnecting() && myReceivedVariable;
    }

so, how can I asign received myData to myReceivedVariable but this class is instantiated evrey time when i make server call

I tried to asign value to global variables or wrap this boolean in a object and use set/get but no success...

Choletski
  • 7,074
  • 6
  • 43
  • 64
  • If you'd like you can save the data received in a SharedPreference and this can be retrieved from anywhere in you application. – Paul Okeke Jul 29 '15 at 16:55
  • yes but I need this value in live time, every request, and using Shared Preferences I am late with one value – Choletski Jul 29 '15 at 17:13
  • If the class you need to receive the data is an activity or a fragment you can send broadcast to them in the onSubscribeMyData method, that way for every call, a broadcast intent will be sent to the classes registered for such broadcast. – Paul Okeke Jul 29 '15 at 17:18
  • well, this is a simple class, for chech internet connection+aviability only, I updated my code for clarity – Choletski Jul 30 '15 at 12:22

0 Answers0