Auto refresh the activity

后端 未结 4 1169
走了就别回头了
走了就别回头了 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 09:09

    try this one, it works well :)

            public void onCreate(Bundle savedInstanceState)  
        {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
    
            this.mHandler = new Handler();
    
            this.mHandler.postDelayed(m_Runnable,5000);
    
    
        }//onCreate
    
        private final Runnable m_Runnable = new Runnable()
        {
            public void run()
    
            {
                Toast.makeText(refresh.this,"in runnable",Toast.LENGTH_SHORT).show();
    
                refresh.this.mHandler.postDelayed(m_Runnable, 5000);            
            }
    
        };//runnable
    
    
        @Override
        protected void onPause() {
            super.onPause();
            mHandler.removeCallbacks(m_Runnable);
            finish();
    
        }
    /*Above method needs to be there otherwise activity will be updating itself again and again even if the activity is paused i.e. back button or home button is pressed*/
    

提交回复
热议问题