As a clarification of the previous question, I will probably do the following, since network activity in the UI thread is also a bad idea:
Create a handler in onCreate ():
mHandler = new Handler();
And still run validation () on your own thread, but modify it slightly:
public void checking() { isInternetPresent = cd.isConnectingToInternet(); if(isInternetPresent) { session.checkLogin(); finish(); } else { mHandler.post(new Runnable() { @Override public void run() { builder.create().show(); finish(); }); } }
Thus, the user interface that we made in the thread and network of the user interface runs in another thread.
source share