evenstevens
Lurker
So I have a Splashscreen at the start of my program, and I want it to display whether or not an active connection has been made to the internet upon this screen. Else the program should exit or display some sort of warning.
However, I realise I need some sort of handler to change the text from "Checking for an internet connection..." to something like "Connection found!", but I have no idea what KIND of handler, as all the ones I know of are UI based.
Any ideas?
Just using connecinfo.setText("blah blah"); just crashes the program, as expected...
Cheers!
However, I realise I need some sort of handler to change the text from "Checking for an internet connection..." to something like "Connection found!", but I have no idea what KIND of handler, as all the ones I know of are UI based.
Any ideas?
Just using connecinfo.setText("blah blah"); just crashes the program, as expected...
Cheers!
Code:
public class Dam extends Activity {
protected boolean active = true;
protected int splashTime = 3000;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
//Thread for making a connection and verifying it
Thread connectivity = new Thread()
{
public void run()
{
try{
//################################################
//############# CONNECTIVITY STUFF ###################
//################################################
TextView connecinfo = (TextView)findViewById(R.id.connectioninfo);
ConnectivityManager connec = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
connecinfo.setText("Checking for an internet connection...");
if (connec.getNetworkInfo(0).getState() == NetworkInfo.State.CONNECTED ||
connec.getNetworkInfo(1).getState() == NetworkInfo.State.CONNECTING )
{
< SHOULD SAY "INTERNET FOUND!" >
}
else if (connec.getNetworkInfo(0).getState() == NetworkInfo.State.DISCONNECTED ||
connec.getNetworkInfo(1).getState() == NetworkInfo.State.DISCONNECTED)
{
< SHOULD SAY "NO INTERNET FOUND!" >
}
}
catch(Exception e1){}
}
};
connectivity.start();
//################################################
//################################################
//################################################
// Thread for displaying the SplashScreen
Thread splashThread = new Thread()
{
@Override
public void run() {
try
{
int waited = 0;
while(active && (waited < splashTime)) {
sleep(100);
waited += 100;
}
}
catch(InterruptedException e) {}
// do nothing
finally {
finish();
startActivity(new Intent("com.beavers.dam.menu"));
stop();
}
}
};
splashThread.start();
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
active = false;
}
return true;
}
}