我有一个测试应用程序,它将问题存储在数据库中。我的FragmentActivity包含一个片段,当从AppBar中选择新问题时,该片段将被替换。当我选择一个大约30次的新问题时,FragmentActivity意外关闭,并将我带回到我之前返回堆栈的Activity。
在我的Logcat级别Verbose上,我没有看到任何与我的应用程序相关的内容。为什么会发生这种情况。
我的xml代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@drawable/buttonshape"
android:orientation="horizontal">
<HorizontalScrollView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<LinearLayout
android:id="@+id/linearLayoutAppbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
</LinearLayout>
</HorizontalScrollView>
<ImageView
android:layout_width="50dp"
android:layout_height="match_parent"
android:src="@drawable/s202_background" />
</LinearLayout>
在调用fragmentTransaction.replace()时,RelativeLayout总是被片段替换; 在LinearLayout下面是我的AppBar,其中按钮以编程方式表示数据库中的每个问题。
单击按钮时,将调用OnClickListener并标识单击了哪个按钮,然后在新方法中调用fragmentTransaction.replace(); 以下是该方法的代码:
private void question1() {
testPrasanjaCursor = BazaNaPrasanja.testDatabase.query(VozackaDbContract.TABLE_NAME_TABELA_TEST, null, null, null, null, null, null);
fragmentTransaction = fragmentManager.beginTransaction();
testPrasanjaCursor.moveToPosition(0);
fragmentTransaction.replace(R.id.fragment_container, fragmentZnaci4);
fragmentTransaction.commit();
testPrasanjaCursor.close();
}
我不知道Sqlite数据库是否导致它或FragmentManager导致我在详细信息中没有与我的Appliaction相关的任何信息。
编辑: 添加了Logcat,这里是所有的logcat,因为我点击模拟器上运行直到它关闭了FragmentActivity:
12-11 13:33:48.802 1722-1722/? I/art: Not late-enabling -Xcheck:jni (already on)
12-11 13:33:48.803 1722-1722/? W/art: Unexpected CPU variant for X86 using defaults: x86_64
12-11 13:33:48.906 1722-1722/mojavozacka.testovi_za_vozacka_dozvola W/System: ClassLoader referenced unknown path: /data/app/mojavozacka.testovi_za_vozacka_dozvola-2/lib/x86_64
12-11 13:33:48.918 1722-1722/mojavozacka.testovi_za_vozacka_dozvola I/InstantRun: Instant Run Runtime started. Android package is mojavozacka.testovi_za_vozacka_dozvola, real application class is null.
12-11 13:33:49.203 1722-1722/mojavozacka.testovi_za_vozacka_dozvola W/System: ClassLoader referenced unknown path: /data/app/mojavozacka.testovi_za_vozacka_dozvola-2/lib/x86_64
12-11 13:33:49.353 1722-1722/mojavozacka.testovi_za_vozacka_dozvola W/art: Verification of java.lang.Object mojavozacka.testovi_za_vozacka_dozvola.PocetnaActivity.access$super(mojavozacka.testovi_za_vozacka_dozvola.PocetnaActivity, java.lang.String, java.lang.Object[]) took 110.107ms
12-11 13:33:49.605 1722-1729/mojavozacka.testovi_za_vozacka_dozvola W/art: Suspending all threads took: 53.041ms
12-11 13:33:49.966 1722-1752/mojavozacka.testovi_za_vozacka_dozvola D/NetworkSecurityConfig: No Network Security Config specified, using platform default
12-11 13:33:50.168 1722-1722/mojavozacka.testovi_za_vozacka_dozvola I/SQLiteAssetHelper: successfully opened database vozacka.db
12-11 13:33:50.170 1722-1722/mojavozacka.testovi_za_vozacka_dozvola I/SQLiteAssetHelper: successfully opened database test.db
12-11 13:33:50.177 1722-1734/mojavozacka.testovi_za_vozacka_dozvola I/art: Background sticky concurrent mark sweep GC freed 10882(1917KB) AllocSpace objects, 11(220KB) LOS objects, 0% free, 45MB/45MB, paused 4.735ms total 215.229ms
12-11 13:33:50.319 1722-1778/mojavozacka.testovi_za_vozacka_dozvola I/OpenGLRenderer: Initialized EGL, version 1.4
12-11 13:33:50.319 1722-1778/mojavozacka.testovi_za_vozacka_dozvola D/OpenGLRenderer: Swap behavior 1
12-11 13:33:50.337 1722-1778/mojavozacka.testovi_za_vozacka_dozvola E/EGL_emulation: tid 1778: eglSurfaceAttrib(1174): error 0x3009 (EGL_BAD_MATCH)
12-11 13:33:50.337 1722-1778/mojavozacka.testovi_za_vozacka_dozvola W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x7d21b2f6f780, error=EGL_BAD_MATCH
12-11 13:33:50.415 1722-1734/mojavozacka.testovi_za_vozacka_dozvola I/art: Background partial concurrent mark sweep GC freed 10885(956KB) AllocSpace objects, 6(120KB) LOS objects, 8% free, 44MB/48MB, paused 19.305ms total 217.880ms
12-11 13:33:53.844 1722-1722/mojavozacka.testovi_za_vozacka_dozvola I/SQLiteAssetHelper: successfully opened database vozacka.db
12-11 13:33:53.858 1722-1722/mojavozacka.testovi_za_vozacka_dozvola I/SQLiteAssetHelper: successfully opened database test.db
12-11 13:33:53.866 1722-1734/mojavozacka.testovi_za_vozacka_dozvola W/art: Suspending all threads took: 7.410ms
12-11 13:33:53.962 1722-1778/mojavozacka.testovi_za_vozacka_dozvola E/EGL_emulation: tid 1778: eglSurfaceAttrib(1174): error 0x3009 (EGL_BAD_MATCH)
12-11 13:33:53.962 1722-1778/mojavozacka.testovi_za_vozacka_dozvola W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x7d21b2f6f040, error=EGL_BAD_MATCH
12-11 13:33:55.979 1722-1729/mojavozacka.testovi_za_vozacka_dozvola W/art: Suspending all threads took: 15.611ms
12-11 13:33:56.304 1722-1778/mojavozacka.testovi_za_vozacka_dozvola E/EGL_emulation: tid 1778: eglSurfaceAttrib(1174): error 0x3009 (EGL_BAD_MATCH)
12-11 13:33:56.304 1722-1778/mojavozacka.testovi_za_vozacka_dozvola W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x7d21b2f6f780, error=EGL_BAD_MATCH
12-11 13:33:58.573 1722-1722/mojavozacka.testovi_za_vozacka_dozvola W/IInputConnectionWrapper: finishComposingText on inactive InputConnection
12-11 13:34:00.499 1722-1729/mojavozacka.testovi_za_vozacka_dozvola W/art: Suspending all threads took: 8.897ms
12-11 13:34:01.755 1722-1734/mojavozacka.testovi_za_vozacka_dozvola I/art: WaitForGcToComplete blocked for 5.076ms for cause Background
12-11 13:34:05.741 1722-1778/mojavozacka.testovi_za_vozacka_dozvola E/EGL_emulation: tid 1778: eglSurfaceAttrib(1174): error 0x3009 (EGL_BAD_MATCH)
12-11 13:34:05.741 1722-1778/mojavozacka.testovi_za_vozacka_dozvola W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x7d21b2f6f040, error=EGL_BAD_MATCH
12-11 13:34:08.083 1722-1722/mojavozacka.testovi_za_vozacka_dozvola W/IInputConnectionWrapper: finishComposingText on inactive InputConnection
答案 0 :(得分:0)
我不确定我的回答是否可以帮助你,但你可以尝试一下,告诉我它是否与性能相同或不是
slist
答案 1 :(得分:0)
我找到了一个简单的解决方案。在打开25个问题时,我重新创建了相同的Activity。 似乎这个bug与Activity有关,可能每个Activity都可以有多达30个Fragments被替换。