I have developed small project, in which there are three fragments added in a single activity.
I am getting an issue in Nougat only i.e.
Start the application and go from fragment 1 -> fragment 2 and in fragment 2 there is a single button on this button click open external browser and when press back button, activity reload again and start from fragment 1.
In below versions from Nougat it is working perfectly, it back on fragment 2 but in Nougat (Samsung Galaxy s8+) it activity reloads and starts from fragment 1.
so please help me to resolve this issue.
thanks
First check your code in onResume where if you are reloading the ViewPager or setting the currentItem.
Other Reason can be Don't keep activities activated. Can you check in the Developer tools to see if Don't keep activities is on?
You can check it from Device settings Like this:
Settings -> Developer Options -> Don't keep activities
Related
in my app I have a fragment using the dm77/barcodescanner.
I'm working on a shop app, ex: you scan an item -> page of product -> continue shopping -> open another scanner sessione -> etc.
Now, as you can see, because the clinet wants to maintain the back stack, multiple istances of that fragment could be open (but not at the same time).
The first fragment with the scanner works well, the others has a still image, even if I call
scannerView.stopCamera();
scannerView = null;
leaving the first fragment.
NOTE: the other fragment works well if, instead of add we use replace. But that will create problems on the fragment's animations.
After furious debugging, I found how to make all working:
When the fragment is visible / in use, create and add programmatically to your layout the ZXingScannerView, starting the camera and preview;
When the fragment is not visible / used, remove the ZXingScannerView from your layout;
On some android version (like 5.01) be careful to not call startCamera more than one time, otherwise you'll not be able to open it anymore until you restart the app. The error here is caused by dead thread exception.
Hope to have been enough clear and helpful.
Short story:
I got error when use FragmentTransaction.setCustomAnimations(....).
When I checking animation listener is only call onStartAnimation & not call onEndAnimation. (it's only happen when I use some tool optimized ram).
Long story:
Here is follow I test in my app.
Input:
We have 2 fragment A, B. MainActivity will open fragment A then open Fragment B. When user press back -> back to fragment A.
Step:
Open fragment A.
Open fragment B.
Use some tool like battery doctor -> Optimized Ram.
Open app -> Current still in Fragment B.
Press back to go to fragment A.
=> Animation never call onAnimationEnd && APP STUCK. I can do anything in with my app.
Notes: If I don't use some tool for "Optimized Ram" -> It always working as well.
Please help me for fix this bug !
UPDATE
I just got Log when app "lag".
Could not find class 'android.support.v4.app.FragmentTransitionCompat21$1', referenced from method android.support.v4.app.FragmentTransitionCompat21.setEpicenter
I am having a specific problem in my android app. I have 2 activities and the flow is from
Activity 1 to Activity 2.
I press back button from Activity 2 and then it goes to activity 1. This is great. But in some devices if I stay too long on activity 2(Like for days, I check it once in a while ) , and when I press back button it doesn't go back. So I guess history is cleared by android os for getting more memory.
I know that I can manually override onBackPressed() and achieve the functionality, but I need a perfect solution for this. so it will be like
If the history is all right let android handle back, If history is disturbed then I should be able to handle it.
IS there any way to check any issue with history?
I have 3 activities ( say A, B, C were A-is the Launch activity). When I press home button when at activity C, app goes into background. After that, I took my app through all apps list menu. At that time, my launch activity is showing (activity A). When I press back button, It goes to previous activity (C). I want to retain in the same activity (C) while coming back from background. When I run application through Eclipse, It works fine. But when I send Apk file through mail and run it in device, It fails (previous problem occurs ).
I tried with
android:launchMode="standard"
AND
android:alwaysRetainTaskState="true"
in my launch activity (Login activity or A). Any body please help me, Thanks in advance.
Follow following steps to insure that you are following the right practice:
1. Make sure you are using finish(); on the Activity A or B if you want to finish it and dont if you want the back button functionality.
2. Try Implementing onpause() and onresume() even if you are not going to perform any functionality in them. Use super() for them there.
3. Also, in android when you start an activity by clicking on the icon instead of resuming it from already running activities, it exhibits a different behaviour.
I experience a very strange problem.
From the MainActivity of my app, by clicking on one of my menu button, a new screen / fragment called MyFragment is loaded.
On the MyFragment screen there is a button called MyButton. If the MyButton button is clicked, it opens a link on a browser.
The problem is that, from the browser, if I click on the Back device button, the behavior is very different depending on the device I test the app (and you will all agree it should NOT) :
on a Samsung Galaxy Tab 2 tablet, the app gets back to its previous state, with the MyFragment loaded and opened (just as if nothing changed from the moment when I clicked on MyButton).
on a Nexus 4 phone, the app is like reset (and then the MyFragment is not loaded). Basically the previous state is lost.
Any idea ?
Here is the piece of code I call from the MyButton click event.
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse("http://www.example.com"));
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); // I tried this but no luck
startActivity(i);
Thanks in advance.
It sounds like on some phones your Activity is geting killed by the OS. Android has the right to kill any Activity that goes in the background if it needs to reclaim the resources that it's using. This is the expected behavior. To mitigate this, you'll need to manage the Activity Lifecycle. The important thing to note from that page are that onSaveInstanceState() will allow you to save your state if the OS is about to kill your Activity, which will restart the lifecycle with onCreate() and provide you with a Bundle that contains all your saved state information.
Additionally, fragments have their own lifecycle, with the equivalent onSaveInstanceState() method, so any Fragment-specific info should be managed there.
Answer : on the Nexus 4 "Developer options", the "Don't keep activities" option was set to true. That's why...