手记

随时退出程序随时退出程序

 用一个专门的集合类对所有的活动进行管理

[代码]java代码:

?

01

02

03

04

05

06

07

08

09

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

 public class ActivityCollector {

    public static List<activity deep="9"> activities = new ArrayList<>();

    public  static void addActivity(Activity   activity)

    {

        activities.add(activity);

    }

    public static void removeActivity(Activity   activity)

    {

        activities.remove(activity);

    }

    public static void finishAll()

    {

        for(Activity   activity:activities)

        {

//              活动未结束的就要将其销毁

            if(!activity.isFinishing())

            {

                activity.finish();

              

            }

        }

        activities.clear();

    }

}</activity><br>

ps:用于杀死当前程序的进程

android.os.Process.killProcess(android.os.Process.myPid());

原文链接:http://www.apkbus.com/blog-919484-72827.html

0人推荐
随时随地看视频
慕课网APP