重新加载活动,而无需在Android中关闭应用

时间:2019-04-22 05:44:53

标签: android

我的活动中有片段,我想通过菜单刷新页面

@Override
public boolean onOptionsItemSelected(MenuItem item) {

   switch (item.getItemId()) {

       case R.id.item_delete:

           // refrash page
           if(db.getAllDataBuyit().size()>0) {
               db.RemoveBuy_AllItem();
               startActivity(getIntent());
           }

           return true;

       default:

    }
    return super.onOptionsItemSelected(item);
}

2 个答案:

答案 0 :(得分:0)

嗨,您可以在完成后执行startActivity;

@Override
public boolean onOptionsItemSelected(MenuItem item) {

switch (item.getItemId()) {

    case R.id.item_delete:

        // refrash page
        if(db.getAllDataBuyit().size()>0) {
            db.RemoveBuy_AllItem();
            /////////////////////////
             finish();
             startActivity(getIntent());
           /////////////////////////
        }
        return true;
    default:
}
return super.onOptionsItemSelected(item);

}

答案 1 :(得分:0)

Intent i = getBaseContext().getPackageManager().getLaunchIntentForPackage(getBaseContext().getPackageName());
startActivity(i);