I have a splashscreen (for try Internet), if we can't connect, we don't launch app.
So, i have try to found one java class on internet and i have found that :https://stackoverflow.com/a/6987498/5070495
I have adapt the code, but i have an error in
if (SplashScreen.getInstance(this).isOnline()) {
Error :
getInstance(android.content.Context')in 'com.srazzz.package.Splashscreen' cannot be applied to '(anonymous java.lang.thread')
All my class
public class SplashScreen extends Activity {
static Context context;
ConnectivityManager connectivityManager;
NetworkInfo wifiInfo, mobileInfo;
boolean connected = false;
private static SplashScreen instance = new SplashScreen();
public static SplashScreen getInstance(Context ctx) {
context = ctx.getApplicationContext();
return instance;
}
public boolean isOnline() {
try {
connectivityManager = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
connected = networkInfo != null && networkInfo.isAvailable() &&
networkInfo.isConnected();
return connected;
} catch (Exception e) {
System.out.println("CheckConnectivity Exception: " + e.getMessage());
Log.v("connectivity", e.toString());
}
return connected;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
Thread timerThread = new Thread(){
public void run(){
try{
sleep(3000);
}catch(InterruptedException e){
e.printStackTrace();
}finally{
if (SplashScreen.getInstance(this).isOnline()) {
Intent i = new Intent(SplashScreen.this, MainActivity.class);
startActivity(i);
} else {
//Toast t = Toast.makeText("test").show();
//Log.v("Home", "############################You are not online!!!!");
Intent i = new Intent(SplashScreen.this, chatonly.class);
startActivity(i);
}
}
}
};
timerThread.start();
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
finish();
}
}