The stream in onCreate() sets the value to true , but after using the stream, the global variable is displayed as false .
How to correctly change it in the stream so that after that it has visibility outside the stream (with the data assigned to it in the stream)?
public class MainActivity extends Activity { boolean access; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); txt=(TextView) findViewById(R.id.textView); new Thread(new Runnable() { @Override public void run(){ if (checkInternet()) { access = true; } else { access = false; } } }).start(); Log.d("my_tag", "AFTER Thread access is "+access); // show access as "false" } }
volatile- ermak0ff