REFRESH ACTIVITY ANDROID EXAMPLE
FIRST OF CREATE ONE ACTIVITY AND TWO OBJECT CREATA SHOW BELOW CODE....
public class TimerActivity extends Activity {
Timer time;
int counter=0;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void onResume() // CREATE ONE METHOD
{
super.onResume();
time=new Timer();
time.schedule(new TimerTask() {
@Override
public void run()
{
runOnUiThread(new Runnable() {
public void run()
{
temp();
}
});
}
}, 0,5000); // SET TIME FRO REFRESH ACTIVITY HERE 5 SECOND AFTER REFRESH ACTIVITY
}
private void temp()
{
counter++;
Toast.makeText(getApplicationContext(), counter+"", Toast.LENGTH_SHORT).show();
}
public void onPause()
{
time.cancel();
super.onPause();
}
}
FIRST OF CREATE ONE ACTIVITY AND TWO OBJECT CREATA SHOW BELOW CODE....
public class TimerActivity extends Activity {
Timer time;
int counter=0;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void onResume() // CREATE ONE METHOD
{
super.onResume();
time=new Timer();
time.schedule(new TimerTask() {
@Override
public void run()
{
runOnUiThread(new Runnable() {
public void run()
{
temp();
}
});
}
}, 0,5000); // SET TIME FRO REFRESH ACTIVITY HERE 5 SECOND AFTER REFRESH ACTIVITY
}
private void temp()
{
counter++;
Toast.makeText(getApplicationContext(), counter+"", Toast.LENGTH_SHORT).show();
}
public void onPause()
{
time.cancel();
super.onPause();
}
}
VIEW MY TUTORIAL
ReplyDelete