首页启动问题,重新启动后,碎片 [英] Home Launcher issue with Fragments after reboot

查看:108
本文介绍了首页启动问题,重新启动后,碎片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发将用于在工业环境中,如手持接口,分布和preconfigured通过我的工作场所的应用程序。我正在做的主页启动运行,这样将有片剂不太诱惑失踪的应用程序。

I am developing an application that will be used in an industrial setting as a handheld interface, distributed and preconfigured by my workplace. I am working on making the application run as the Home Launcher so that there will be less temptation for the tablets to "go missing".

背景

我有以下我的清单,使应用程序启动:

I have the following in my manifest to make the application a Launcher:

<intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.HOME" />
    <category android:name="android.intent.category.DEFAULT"/>
</intent-filter>

(我可以发布更多的清单,如果有必要的)

(I can post more of the manifest if necessary)

我的应用程序的结构如下:

My application's structure is as follows:

  1. USB_Stuff延伸活动
  2. 在主延伸USB_Stuff
  3. 在用户界面扩展片段
  4. SQLiteHelper扩展SQLiteOpenHelper

主处理所有片段的通信和交易。 主也是注册的内容清单中的&LT下,活动&GT; name属性。

The "Main" handles all of the fragment communications and transactions. The "Main" is also what is registered in the manifest under the <activity> name attribute.

我也有一个 BOOT_COMPLETED 接收器,启动我的应用程序,该清单中的

I also have a BOOT_COMPLETED receiver within the manifest that launches my application.

问题

解决现在一切都很正常,如果我从Eclipse运行程序,并使用它。不过,如果我重新启动设备在启动的第一个屏幕,其中包含一个的ListView <上(在两个华硕的Nexus 7(4.2.2)和三星Galaxy Tab 2 7.0(4.1.1)进行测试) / code>如下:

然后我可以选择的项目形成的列表,它会带我到下一个片段包含三个按钮代替列表:

解决如果我点击第二个上图中的红色方框内,然后我可以选择不同的项目构成了的ListView 最多一次,之后我在冲空间触碰,一旦停用onClickListener(?)。但如果我点击了三个明显的按钮中的一个,应用程序执行它的点击通过对previous屏幕的onClick 方法来代替。这种行为继续在多个屏幕和停止一旦应用程序达到 TableLayouts

SOLVED If I click within the red boxes on the second image above, then I can select a different item form the ListView up to one time, after I touch in the red space once it deactivates the "onClickListener"(?). Although if I click on one of the three visible buttons, the application performs it's onClick method instead of clicking through to the previous screen. This behavior continues on for multiple screens and stops once the application reaches the TableLayouts.

另外一个问题,我觉得可能是相关的,就是后退按钮和我后来的取消,都应该弹出回栈的某些点或者将根本不工作或执行不正确的弹出位置的按钮。

Another issue, that I feel may be related, is that the back button and my later cancel buttons that are supposed to pop the back stack to certain points either will not function at all or perform an incorrect pop location.

更新:的实施低于我的解决方案后,我已经解决了大部分问题,但​​如果我开始使用应用程序前2秒(约)内,则我还是结了随机背叠在大跌眼镜的位置。

UPDATE: After implementing my solution below, I have solved most issues, except if I start to use the application within the first 2 seconds (about) then I still end up with the random back stack locations upon popping.

我想通了迄今为止...

如果我注释掉主页启动意图过滤器和使用 BOOT_COMPLETED 过滤器来启动应用程序,然后,一切工作正常了。

If I comment out the Home Launcher intent-filter and use a BOOT_COMPLETED filter to launch the app, then everything functions properly again.

另外,我补充日志报表在整个程序中查看后面的堆栈条目数,随后通过应用程序相同的确切路径时,它运行正常,没有和数量是否一致,但如果我点击红色框,该应用程序将增加碎片后退堆栈,它不应该。这使我相信,这不是一个问题,在后面堆栈也可以通过泄露了自己的看法额外的项目。

Also, I added log statements to view the back stack entry count throughout the program and followed the same exact pathway through the application when it was running properly and not and the numbers are consistent, yet if I click in the red boxes, the app will add fragments to the back stack that it should not. This leads me to believe that it is not an issue with extra items on the back stack that may also be leaking their views through.

解决编辑:的我加一个按钮,没什么可说是 match_parent 第二个片段做在宽度和高度,当我试图通过点击到previous片段的的ListView ,它没有工作。看来,如果背景是可点击,而previous片段被设置为背景/壁纸(?)。

SOLVED I added a button that did nothing to the second fragment that was match_parent in both width and height and when I tried to click through to the previous fragment's ListView, it did NOT work. It seems as if the background is "clickable" and that the previous fragment is being set as the "background/wallpaper"(?).

问题

ANSWERED 1),这是什么原因,这些布局泄漏的片段片段的重新启动后?

- 部分已回答的2)什么会导致背部/取消键( popBackStack(...))不重新启动后正常运行?

PARTIALLY ANSWERED 2) What could cause the back/cancel buttons (popBackStack(...)) to not function properly after a reboot?

更多code可应要求提供方便的解决方案。

推荐答案

问题1:自从似乎布局并没有被完全删除,我决定尝试删除所有的听众所有子项目中的每个片段的的onDestroy 。我最终找到方法 removeAllViewsInLayout(),决定试试下面的code:

QUESTION 1: Since it seems that the layout was not being completely removed I decided to try removing all the listeners to all the child items in each fragment's onDestroy. I ended up finding the method removeAllViewsInLayout() and decided to try the following code:

@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        container.removeAllViewsInLayout();
        return inflater.inflate(R.layout.welcome_select_cabinet, container, false);
    }

本走进每一个片段,使得之前的布局被夸大为布局的ViewGroup的子项将被清除。这解决了点击通过以previous片段的项目的问题。

This went into each fragment so that before the layout was inflated for that layout the ViewGroup's child items would be cleared. This solved the issue of the "clicking through" to the previous fragment's items.

问2:我加了后的setContentView紧随其后的()在我的主要活动:

QUESTION 2: I have added the following immediately after setContentView() in my "Main" activity:

getFragmentManager().popBackStack();

,然后当我加入的第一个片段中的的onCreate 主的,我改变了以下内容:

And then when I add the first fragment in the onCreate of "Main", I changed the following:

Welcome welcomeFragment = new Welcome();
getFragmentManager().beginTransaction().add(R.id.parent_container, welcomeFragment, "welcomeSelect").commit();

这样:

WelcomeSelectCabinet welcomeSelection = new WelcomeSelectCabinet();
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.add(R.id.parent_container, welcomeSelection, "welcomeSelect");
transaction.addToBackStack(null);
transaction.commit();

现在,如果我等待约2秒后重新开机,然后开始使用的应用程序,我会不会遇到任何错误。但是,如果我使用的应用程序马上再有,直到我再次重启,并等待2秒钟之前,同样的错误。

Now if I wait for about 2 seconds after a reboot, and then start to use the app, I will not encounter any errors. But if I use the app immediately then there are the same errors as before until I reboot again and wait for 2 seconds.

编辑:我为了占〜2秒加载加5秒的加载屏幕,并且似乎已经解决了这一问题上的Nexus 7,但不是银河标签2.我改变5至10秒,因为Galaxy Tab的2似乎需要大约两倍的时间来启动,这似乎已经解决了这一问题。

I added a 5 second load screen in order to account for the ~2 second "loading" and that seems to have fixed the problem on the Nexus 7 but not the Galaxy Tab 2. I changed the 5 seconds to 10 seconds since the Galaxy Tab 2 seems to take about twice as long to boot and this seemed to have fixed the problem.

编辑:为了使装载更兼容,我能扎入 BOOT_COMPLETED 接收器和设置存储在一个布尔共享preferences 这将决定哪些片段要加载有根据的价值,这是重新在关闭的BroadcastReceiver。

To make loading more compatible, I was able to tie it into the BOOT_COMPLETED receiver and set a Boolean that is stored in SharedPreferences that will determine which fragments to load based on the value, which is reset on the SHUTDOWN BroadcastReceiver.

这篇关于首页启动问题,重新启动后,碎片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆