Auto refresh the activity

后端 未结 4 1178
走了就别回头了
走了就别回头了 2020-12-05 08:39

In my application I have a activity that displays contents from internet..... I just want to know how can I auto refresh the activity.....

Please suggest and provide

4条回答
  •  难免孤独
    2020-12-05 08:54

    This code for If you want first create the view and after that refreshing page at specified time span then use following code.(here mention refreshing rate is 20 seconds) It Works Fine and Automatic refresh in every 20 seconds.

    public class MainActivity extends Activity {
    Handler mHandler;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
            this.mHandler = new Handler();
            m_Runnable.run();
    
    }
        private final Runnable m_Runnable = new Runnable()
        {
            public void run()
    
            {
                Toast.makeText(MainActivity.this,"in runnable",Toast.LENGTH_SHORT).show();
    
                MainActivity.this.mHandler.postDelayed(m_Runnable,20000);            
            }
    
        };
    }
    

提交回复
热议问题