I'm having a problem and i Can't solve it. In my activity, I got a function that returns if the phone is connected to Wifi or 3g . When I open onCreate() I make the initialization of variables and I run a TimerTask for 5 in 5 seconds, to test if the connection is "true".
If the connection is On I set an Enter button visible to the user click to advance to my next activity, and I set 2 texts, to open a message "CLICK enter to begin".
The problem is in the TimerTask, i get an error saying :"only the original thread that created a view hierarchy can touch its views". How do I resolve it???
code:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.entry_activity);
enter = (Button) findViewById(R.id.button_enter);
intent = new Intent(EntryActivity.this, MainActivity.class);
warning = (TextView) findViewById(R.id.textView_warning);
turnOn = (TextView) findViewById(R.id.textView_turnOn);
Context context=this;
t = new Timer();
t.schedule( new TimerTask() {
@Override
public void run() {
if(isNetAvailable(getApplicationContext())){
enter.setVisibility(View.VISIBLE);
turnOn.setText("Click Enter to begin");
turnOn.setTextColor(R.color.Green);
t.cancel();
}
}
},0, 1000);
enter.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub~
startActivity(intent);
}
});
}
Note: In the beggining of the app, I'm supposing that ther's no Internet connection, that's why I'm changing the TextColor to green and the turnOn to "Click Enter.." (in the beggining the text presented is "No internet, turn it on. Waiting"...