Android Refresh activity when returns to it

后端 未结 7 1985
Happy的楠姐
Happy的楠姐 2021-02-07 10:41

I need a little help with refreshing one of my activities in my application. I\'m using tab host activity and connecting to web service and downloading some data from one of my

7条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-07 11:26

    on button press:

    Intent intent = new Intent(this, SyncActivity.class);
            //intent.putExtra("someData", "Here is some data");
            startActivityForResult(intent, 1);
    

    Then in the same Activity class:

       @Override
         protected void onActivityResult(int requestCode, int resultCode, Intent data) {
          super.onActivityResult(requestCode, resultCode, data);
          if(resultCode==RESULT_OK){
             Intent refresh = new Intent(this, InitialActivity.class);
             startActivity(refresh);
             this.finish();
          }
         }
    

    The Sync Activity would have:

    setResult(RESULT_OK, null);
    finish();
    

提交回复
热议问题