简体   繁体   English

应用程序进程被杀死后片段onCreate

[英]Fragments onCreate after app process been killed

I have an app which is basically a launcher with a main activity and view pager fragments and i just noticed that if i launch an app from my app and my app gets killed when i return somehow the on create fragment function get´s called first that my on create main activity function. 我有一个应用程序,它基本上是一个主要活动和视图分页器片段的启动器,我只是注意到,如果我从我的应用程序启动一个应用程序,我的应用程序被杀死,当我以某种方式返回创建片段函数时首先调用我在创建主要活动功能。

This eventually crashes my app because i get a list of all applications using the main activity first and then each pager view fragment will get a sub list from the main list. 这最终导致我的应用程序崩溃,因为我首先使用主要活动获取所有应用程序的列表,然后每个寻呼机视图片段将从主列表中获取子列表。 The app runs fine when executed for the first time because android runs first the on create of the main activity and then the on create of the fragments 应用程序第一次执行时运行正常,因为android首先运行主要活动的创建,然后运行片段的创建

So how can i solve this? 那我怎么解决这个问题呢? is there a way to call first the onCreate Main Activity function? 有没有办法首先调用onCreate主要活动功能? or is there a better way do to this? 或者有更好的方法吗?

The app gives illegal argument exception when i try to create the shorter list, and since the main list is only filled be the main activity when i return to my app the main list is empty giving me the exception 当我尝试创建较短的列表时,应用程序提供非法的参数异常,并且由于主要列表仅在我返回到我的应用程序时填充为主要活动,因此主列表为空,给出了异常

The code: 编码:

` `

    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.grid, null);

        GridView gridview = (GridView) view.findViewById(R.id.gridview);

        int starterPosition;

        starterPosition = 16 * position;
        int enderPosition = starterPosition + 16;

        if (enderPosition > appsList.size()) {
            enderPosition = appsList.size();
        }


        ArrayList<App> shorterList = new ArrayList<App>(appsList.subList(
                starterPosition, enderPosition));

        final AppLauncherAdapter grid = new AppLauncherAdapter(ctx, shorterList);

        gridview.setAdapter(grid);

        gridview.setSelector(R.color.trans);


        return gridview;
    }

` `

There is a method called onActivityCreated that you should use specifically for this purpose. 有一个名为onActivityCreated的方法,您应该专门用于此目的。 onActivityCreated will always be called after the Activity 's onCreate method. onActivityCreated将始终在ActivityonCreate方法之后调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果App进程终止,捆绑包如何发送到onCreate? - How is bundle sent to onCreate if App process killed? 操作系统终止进程后重新启动应用程序 - Restarting the app after process has been killed by the OS 为什么在杀死进程后重新创建活动时onDestroy会重新创建片段 - Why onDestroy recreates the Fragments when Activity recreate after process killed 应用被杀死后,ViewPager出现NullPointerException - NullPointerException with ViewPager after the app has been killed 如何检查onCreate是否已杀死同一活动的先前android进程? - how to check in onCreate that the previous android process of the same activity has been killed? 应用程序进程被杀死后,片段无法恢复 - Fragment is not restored after app process is killed 应用被杀死并恢复后,如何避免Activity中出现多个片段实例? - How to avoid multiple instances of fragments in Activity after app is killed and resumed? 我的Android APP进程已被终止,但仍在RunningTask中 - My Android APP's process has been killed, but still in RunningTask 如何知道一个进程(app)是否被杀死? - how to know whether a process(app) has been killed? 一个进程被杀死后,能否重用一个片段? - Can one reuse a fragment after process has been killed?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM