Add and remove fragments frequently - android

I have an activity and it consists of two fragments. The app switches between one of these fragments very frequently. I am using code like this to switch between fragments,
fragmentTransaction
.setCustomAnimations(R.anim.enter_from_right, R.anim.exit_to_left)
.remove(fragment2)
.add(R.id.common_container, fragment1)
.commit();
The above code removes fragment2 and adds fragment1. The above code works fine but when I try to switch between fragments frequently an exception showing this trace is coming up,E/AndroidRuntime( 8809): java.lang.IllegalStateException: No activity
E/AndroidRuntime( 8809): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1054)
E/AndroidRuntime( 8809): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1049)
E/AndroidRuntime( 8809): at android.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:1869)
E/AndroidRuntime( 8809): at android.app.Fragment.performActivityCreated(Fragment.java:2067)
E/AndroidRuntime( 8809): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:912)
E/AndroidRuntime( 8809): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
E/AndroidRuntime( 8809): at android.app.BackStackRecord.run(BackStackRecord.java:834)
E/AndroidRuntime( 8809): at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1452)
E/AndroidRuntime( 8809): at android.app.FragmentManagerImpl$1.run(FragmentManager.java:447)
E/AndroidRuntime( 8809): at android.os.Handler.handleCallback(Handler.java:739)
E/AndroidRuntime( 8809): at android.os.Handler.dispatchMessage(Handler.java:95)
E/AndroidRuntime( 8809): at android.os.Looper.loop(Looper.java:135)
E/AndroidRuntime( 8809): at android.app.ActivityThread.main(ActivityThread.java:5254)
E/AndroidRuntime( 8809): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 8809): at java.lang.reflect.Method.invoke(Method.java:372)
E/AndroidRuntime( 8809): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
E/AndroidRuntime( 8809): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
I know that i can use replace instead of adding and removing, but there are other fragments where i cannot replace because the container is different.
Can anyone help me ?
Edit:
Even replacing fragment also causes this exception

Related

Uncaught exception in Firebase Database runloop (20.0.6)

I get the following error stack trace when trying to navigate to a screen that uses Firebase Realtime Database for the second time after running the application on my android device.
java.lang.RuntimeException: Uncaught exception in Firebase Database runloop (20.0.6). If you are not already on the latest version of the Firebase SDKs, try updating your dependencies. Should this problem persist, please file a report at https://github.com/firebase/firebase-android-sdk
E/AndroidRuntime( 3934): at com.google.firebase.database.android.AndroidPlatform$1$1.run(AndroidPlatform.java:96)
E/AndroidRuntime( 3934): at android.os.Handler.handleCallback(Handler.java:938)
E/AndroidRuntime( 3934): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 3934): at android.os.Looper.loopOnce(Looper.java:210)
E/AndroidRuntime( 3934): at android.os.Looper.loop(Looper.java:299)
E/AndroidRuntime( 3934): at android.app.ActivityThread.main(ActivityThread.java:8168)
E/AndroidRuntime( 3934): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 3934): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:556)
E/AndroidRuntime( 3934): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1037)
E/AndroidRuntime( 3934): Caused by: java.lang.RuntimeException: java.lang.AssertionError: hardAssert failed: listen() called twice for same QuerySpec.
E/AndroidRuntime( 3934): at com.google.firebase.database.core.persistence.NoopPersistenceManager.runInTransaction(NoopPersistenceManager.java:131)
E/AndroidRuntime( 3934): at com.google.firebase.database.core.SyncTree.addEventRegistration(SyncTree.java:549)
E/AndroidRuntime( 3934): at com.google.firebase.database.core.SyncTree.keepSynced(SyncTree.java:857)
E/AndroidRuntime( 3934): at com.google.firebase.database.core.Repo.keepSynced(Repo.java:772)
E/AndroidRuntime( 3934): at com.google.firebase.database.core.Repo.keepSynced(Repo.java:767)
E/AndroidRuntime( 3934): at com.google.firebase.database.Query$4.run(Query.java:267)
E/AndroidRuntime( 3934): at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:463)
E/AndroidRuntime( 3934): at java.util.concurrent.FutureTask.run(FutureTask.java:264)
E/AndroidRuntime( 3934): at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:307)
E/AndroidRuntime( 3934): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1137)
E/AndroidRuntime( 3934): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:637)
E/AndroidRuntime( 3934): at java.lang.Thread.run(Thread.java:1012)
E/AndroidRuntime( 3934): Caused by: java.lang.AssertionError: hardAssert failed: listen() called twice for same QuerySpec.
E/AndroidRuntime( 3934): at com.google.firebase.database.connection.ConnectionUtils.hardAssert(ConnectionUtils.java:67)
E/AndroidRuntime( 3934): at com.google.firebase.database.connection.PersistentConnectionImpl.listen(PersistentConnectionImpl.java:391)
E/AndroidRuntime( 3934): at com.google.firebase.database.core.Repo$5.startListening(Repo.java:206)
E/AndroidRuntime( 3934): at com.google.firebase.database.core.SyncTree.setupListener(SyncTree.java:918)
E/AndroidRuntime( 3934): at com.google.firebase.database.core.SyncTree.access$1000(SyncTree.java:79)
E/AndroidRuntime( 3934): at com.google.firebase.database.core.SyncTree$13.call(SyncTree.java:645)
E/AndroidRuntime( 3934): at com.google.firebase.database.core.SyncTree$13.call(SyncTree.java:550)
E/AndroidRuntime( 3934): at com.google.firebase.database.core.persistence.NoopPersistenceManager.runInTransaction(NoopPersistenceManager.java:126)[1]][1]
My pubspec.yaml file:
My Flutter doctor output:

simple_pdf_viewer crashes on api level 30 [Flutter]

App crashes while trying to open pdf in flutter. I have used "simple_pdf_viewer: ^0.2.2".
I have attached the details of the crash report below :
Library link : simple_pdf_viewer .
Caused by: java.lang.IllegalStateException: Expected Android API level 21+ but was 30
java.lang.ExceptionInInitializerError
E/AndroidRuntime( 7294): at okhttp3.internal.platform.Platform.get(Platform.java:85)
E/AndroidRuntime( 7294): at okhttp3.OkHttpClient.newSslSocketFactory(OkHttpClient.java:296)
E/AndroidRuntime( 7294): at okhttp3.OkHttpClient.(OkHttpClient.java:262)
E/AndroidRuntime( 7294): at okhttp3.OkHttpClient$Builder.build(OkHttpClient.java:1054)
E/AndroidRuntime( 7294): at com.liyuanhust.pdfviewer.FileLoader.(FileLoader.kt:155)
E/AndroidRuntime( 7294): at com.liyuanhust.pdfviewer.PdfView.(PdfView.kt:30)
E/AndroidRuntime( 7294): at com.liyuanhust.pdfviewer.PdfViewerFactory.create(PdfViewerFactory.kt:14)
E/AndroidRuntime( 7294): at io.flutter.plugin.platform.SingleViewPresentation.onCreate(SingleViewPresentation.java:186)
E/AndroidRuntime( 7294): at android.app.Dialog.dispatchOnCreate(Dialog.java:419)
E/AndroidRuntime( 7294): at android.app.Dialog.show(Dialog.java:313)
E/AndroidRuntime( 7294): at android.app.Presentation.show(Presentation.java:257)
E/AndroidRuntime( 7294): at io.flutter.plugin.platform.VirtualDisplayController.(VirtualDisplayController.java:95)
E/AndroidRuntime( 7294): at io.flutter.plugin.platform.VirtualDisplayController.create(VirtualDisplayController.java:48)
E/AndroidRuntime( 7294): at io.flutter.plugin.platform.PlatformViewsController$1.createVirtualDisplayForPlatformView(PlatformViewsController.java:207)
E/AndroidRuntime( 7294): at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.create(PlatformViewsChannel.java:104)
E/AndroidRuntime( 7294): at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.onMethodCall(PlatformViewsChannel.java:59)
E/AndroidRuntime( 7294): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:233)
E/AndroidRuntime( 7294): at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
E/AndroidRuntime( 7294): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:738)
E/AndroidRuntime( 7294): at android.os.MessageQueue.nativePollOnce(Native Method)
E/AndroidRuntime( 7294): at android.os.MessageQueue.next(MessageQueue.java:335)
E/AndroidRuntime( 7294): at android.os.Looper.loop(Looper.java:183)
E/AndroidRuntime( 7294): at android.app.ActivityThread.main(ActivityThread.java:7656)
E/AndroidRuntime( 7294): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 7294): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
E/AndroidRuntime( 7294): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
E/AndroidRuntime( 7294): Caused by: java.lang.IllegalStateException: Expected Android API level 21+ but was 30
E/AndroidRuntime( 7294): at okhttp3.internal.platform.AndroidPlatform.buildIfSupported(AndroidPlatform.java:238)
E/AndroidRuntime( 7294): at okhttp3.internal.platform.Platform.findPlatform(Platform.java:202)
E/AndroidRuntime( 7294): at okhttp3.internal.platform.Platform.(Platform.java:79)
E/AndroidRuntime( 7294): ... 26 more
[SOLVED]
I have solved this issue.
Anyone referring to this in future, change the okhttp dependency version to 3.14.7 in the simple_pdf_viewer library present in /flutter/.pub-cache/hosted/pub.dartlang.org/ , it is working fine in android 11 as well.

java.lang.IllegalArgumentException: provider doesn't exist: network

I have compiled an system from AOSP and fastboot it into Nexus 7. I am now trying to write a very simple app to test the location updates through Network provider.
I have a sim card installed and enabled all the settings but I always get the errors shown below. It seems like there is no network provider. But How can I enabled it?? I have been stuck in this for ages and have no clues.(GPS is working fine)
D/PbdTrial( 4527): Network provider NOT enabled
D/AndroidRuntime( 4527): Shutting down VM
E/AndroidRuntime( 4527): FATAL EXCEPTION: main
E/AndroidRuntime( 4527): Process: com.example.jack.pbdtrial, PID: 4527
E/AndroidRuntime( 4527): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.jack.pbdtrial/com.example.jack.pbdtrial.MainActivity}: java.lang.IllegalArgumentException: provider doesn't exist: network
E/AndroidRuntime( 4527): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
E/AndroidRuntime( 4527): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
E/AndroidRuntime( 4527): at android.app.ActivityThread.access$800(ActivityThread.java:144)
E/AndroidRuntime( 4527): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
E/AndroidRuntime( 4527): at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime( 4527): at android.os.Looper.loop(Looper.java:135)
E/AndroidRuntime( 4527): at android.app.ActivityThread.main(ActivityThread.java:5221)
E/AndroidRuntime( 4527): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 4527): at java.lang.reflect.Method.invoke(Method.java:372)
E/AndroidRuntime( 4527): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
E/AndroidRuntime( 4527): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
E/AndroidRuntime( 4527): Caused by: java.lang.IllegalArgumentException: provider doesn't exist: network
E/AndroidRuntime( 4527): at android.os.Parcel.readException(Parcel.java:1544)
E/AndroidRuntime( 4527): at android.os.Parcel.readException(Parcel.java:1493)
E/AndroidRuntime( 4527): at android.location.ILocationManager$Stub$Proxy.requestLocationUpdates(ILocationManager.java:584)
E/AndroidRuntime( 4527): at android.location.LocationManager.requestLocationUpdates(LocationManager.java:867)
E/AndroidRuntime( 4527): at android.location.LocationManager.requestLocationUpdates(LocationManager.java:459)
E/AndroidRuntime( 4527): at com.example.jack.pbdtrial.MainActivity.onCreate(MainActivity.java:73)
E/AndroidRuntime( 4527): at android.app.Activity.performCreate(Activity.java:5933)
E/AndroidRuntime( 4527): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
E/AndroidRuntime( 4527): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
Have you added this to your manifest?
<manifest ... >
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
...
</manifest>
Also, to be sure you have enable the location update in your phone setting, you can prompt the user to enable it using this method

How to inject Layout to LayoutInflater in RoboGuice?

I have layout
R.layout.alarm_clock_setting_view
And i want to Inject him into LayoutInflater.
Now i do next :
#InjectView(R.layout.alarm_clock_setting_view)
private RelativeLayout alarmClockSettingView;
...
//in OnCreate
mSettingAlarmClockView = alarmClockSettingView;
...
But that's not worked. What i need to do to inject layout into LayoutInflater?
Error :
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.samsung.clock/com.samsung.clock.views.ClockFragmentActivity}: java.lang.IllegalStateException: Unable to use annotation database(s)
E/AndroidRuntime( 3754): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2658)
E/AndroidRuntime( 3754): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2725)
E/AndroidRuntime( 3754): at android.app.ActivityThread.access$900(ActivityThread.java:172)
E/AndroidRuntime( 3754): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1422)
E/AndroidRuntime( 3754): at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime( 3754): at android.os.Looper.loop(Looper.java:145)
E/AndroidRuntime( 3754): at android.app.ActivityThread.main(ActivityThread.java:5834)
E/AndroidRuntime( 3754): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 3754): at java.lang.reflect.Method.invoke(Method.java:372)
E/AndroidRuntime( 3754): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1388)
E/AndroidRuntime( 3754): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1183)
E/AndroidRuntime( 3754): Caused by: java.lang.IllegalStateException: Unable to use annotation database(s)
E/AndroidRuntime( 3754): at roboguice.RoboGuice.initializeAnnotationDatabaseFinderAndHierarchyTraversalFilterFactory(RoboGuice.java:292)
E/AndroidRuntime( 3754): at roboguice.RoboGuice.getOrCreateBaseApplicationInjector(RoboGuice.java:149)
E/AndroidRuntime( 3754): at roboguice.RoboGuice.getOrCreateBaseApplicationInjector(RoboGuice.java:90)
E/AndroidRuntime( 3754): at roboguice.RoboGuice.getInjector(RoboGuice.java:197)
E/AndroidRuntime( 3754): at roboguice.activity.RoboFragmentActivity.onCreate(RoboFragmentActivity.java:60)
E/AndroidRuntime( 3754): at MainActivity.onCreate(MainActivity.java:95)
E/AndroidRuntime( 3754): at android.app.Activity.performCreate(Activity.java:6221)
E/AndroidRuntime( 3754): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
E/AndroidRuntime( 3754): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2611)
E/AndroidRuntime( 3754): ... 10 more

Robotium with support.v4 ViewCompat throws NoSuchMethodError on load

I'm using Robotium to automate my app testing. My app has 1 activity (ActionBarActivity) and 2 fragments (using support.v4.app.Fragment). The app works fine but when I attempt to run a Robotium test, I get an error when attempting to create a new Solo instance.
solo = new Solo(getInstrumentation(), getActivity());
Logcat output:
java.lang.NoSuchMethodError: No static method setOnApplyWindowInsetsListener(Landroid/view/View;Landroid/support/v4/view/OnApplyWindowInsetsListener;)V in class Landroid/support/v4/view/ViewCompat; or its super classes (declaration of 'android.support.v4.view.ViewCompat' appears in /data/app/com.mycompany.mytrip.test-1/base.apk)
E/AndroidRuntime( 5220): at android.support.v7.app.ActionBarActivityDelegateBase.ensureSubDecor(ActionBarActivityDelegateBase.java:304)
E/AndroidRuntime( 5220): at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:225)
E/AndroidRuntime( 5220): at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:102)
E/AndroidRuntime( 5220): at com.mycompany.mytrip.activities.MainActivity.onCreate(MainActivity.java:38)
E/AndroidRuntime( 5220): at android.app.Activity.performCreate(Activity.java:5933)
E/AndroidRuntime( 5220): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
E/AndroidRuntime( 5220): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
E/AndroidRuntime( 5220): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
E/AndroidRuntime( 5220): at android.app.ActivityThread.access$800(ActivityThread.java:144)
E/AndroidRuntime( 5220): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
E/AndroidRuntime( 5220): at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime( 5220): at android.os.Looper.loop(Looper.java:135)
E/AndroidRuntime( 5220): at android.app.ActivityThread.main(ActivityThread.java:5221)
E/AndroidRuntime( 5220): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 5220): at java.lang.reflect.Method.invoke(Method.java:372)
E/AndroidRuntime( 5220): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
E/AndroidRuntime( 5220): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
W/ActivityManager( 1229): Error in app com.mycompany.mytrip running instrumentation ComponentInfo{com.mycompany.mytrip.test/android.test.InstrumentationTestRunner}:
W/ActivityManager( 1229): java.lang.NoSuchMethodError
W/ActivityManager( 1229): java.lang.NoSuchMethodError: No static method setOnApplyWindowInsetsListener(Landroid/view/View;Landroid/support/v4/view/OnApplyWindowInsetsListener;)V in class Landroid/support/v4/view/ViewCompat; or its super classes (declaration of 'android.support.v4.view.ViewCompat' appears in /data/app/com.mycompany.mytrip.test-1/base.apk)
D/AndroidRuntime( 5209): Shutting down VM
Any suggestion much appreciated!

Categories

Resources