I'm newbie to Android Application development, so really appreciate guidance on this.
When I have connection to my server, the main page will load instantly with all text and buttons. However, if im not connected to the network, the page will shows blank white screen for about 10sec after I open the application before the whole screen showing.
I think this is because the app are trying to connect to the server, before sending error message as a textview. how do i make it so that the screen shows 1st and the connecting to server run in the background and later show the result whether its connected or not. below are the code that i used, in onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TrackingNo = findViewById(R.id.TrackingNoTxt);
ConnectionStatus = findViewById(R.id.connectionStatTxt);
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA}, PackageManager.PERMISSION_GRANTED);
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
try {
Class.forName(Classes);
connection = DriverManager.getConnection(url, username, password);
ConnectionStatus.setText("Connection Established!");
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
ConnectionStatus.setText("Error connecting to the server. Please check your connection!");
}
}
Any suggestions will gladly be appreciated. Thanks