How to send my activity to background and resume?

后端 未结 2 2015
后悔当初
后悔当初 2021-01-13 20:23

I want to load data from Internet.

While loading data I show a loading indicator. What I want to do when pressing back, I cancel the loading indicator via onC

相关标签:
2条回答
  • 2021-01-13 21:14

    Simply use:

    moveTaskToBack(true);
    
    0 讨论(0)
  • 2021-01-13 21:20

    Basically you want to switch the order of the current background and the previous background. To do this, you can start the previous activity and use the FLAG_ACTIVITY_REORDER_TO_FRONT flag:

    Intent intent = new Intent(this, MyPreviousActivity.class);
    intent.setFlags(FLAG_ACTIVITY_REORDER_TO_FRONT);
    startActivity(intent);
    

    So if you have tasks A, B, C and task C calls startActivity() with activity B, then B will be brought to the front of the activity stack, with the resulting order A, C, B, which is what you were asking for.

    See Intent.FLAG_ACTIVITY_REORDER_TO_FRONT

    0 讨论(0)
提交回复
热议问题