Don't recycle old instance of same activity - java

I have a UserProfile Activity which is composed of different RecyclerView in tabs, there is a tab friends where i can click another user and a new instance of the same UserProfile will start.
The only problem is when i go press back from an instance: i've overrided the OnBackPressed which only contains finish() method, i will be redirected to the previous UserProfile instance, but all the RecyclerView and the profilePicture in the activity are still the same of the activity i've just finished.
I think it's due to the fact that they are RecyclerView but don't know how to solve it.

Related

Is it possible to prevent WebView or any View from being destroyed?

So my understanding is that View has different lifecycle then Fragment, I have noticed that by adding confingChanges to MainActivity android:name=".MainActivity" android:configChanges="orientation|screenSize|keyboardHidden", my WebView (or maybe the whole Fragment) is not being destroyed on rotation (or at least it seems like it is not being destroyed) i.e the Website is not being reloaded, so how does android does this? Is there any way to save the WebView when the fragment is being destroyed and then pass this webView to the fragment when it is being created?
I thought maybe following would work: detach the view in the onPause or any other method down the line (Fragments Lifecycle) save the View somewhere and then pass it back in the onCreateView method?
Background to the App: there is bottom navigation Bar which has 4 elements when one of these elements is clicked a new fragment is created and displayed inside of the main activity, while the Fragment before is being destroyed (this is achived using getSupportFragmentMenager().beginTransaction().replace().commit();), one of these Fragments has WebView in it, i would like to prevent the WebView from being destroyed?
I have achived the following: I am saving the state of the WebView inside onPause method and inside onSavedInstace method (for the cases when the activity itself gets destroyed), but the problem with this is that the Input that the user puts inside forms during the session but not sending them gets lost on reload/restore of the WebView, so would like to save the Webview so that even this remains when the user comes back to the site.

Retrieving an object when coming back to Activity

Here's the context of my question :
Context
I've made a Recyclerview that dysplay items thanks to an object called "identity_candle". When I click on items, it brings me to another activity with more description over the item. On this activity, there is a button to view more details about it that needs another layout by itself.
So when I click on the button it lands me on another activity.
IN SUMMARY, MainActivity (RecyclerVIew) => ItemActivity => "press button" => Activity or Fragment ? (Come back : Activity or Fragment => ItemActivity (keep previous object)
Problem
But when I want to come back to the previous activity it brings me error because the object state "identity_candle" is null.
Questions
What should I do ? Should I use fragment instead of activity when I press button ? (I've seen that object keeps their state between fragment and Activity but I'm not sure) Should I use SharedPreference ? If I want to create Fragment should I extends Fragment or ActivityFragment ?
This seems heavily rooted in understanding the Activity lifecyle. You'll likely want to go through that training if you haven't already. An understanding of onSaveInstanceState(), onRestoreInstanceState(), and Parcelables should get you there.

RecyclerView inside PagerAdapter

I have a main fragment that contains a viewpager. This viewpager gets the same secondary fragment (different from the main one) but with different parameters every time. Inside the said secondary fragment that is inside the viewpager, i have a recyclerview. Inside these recyclerviews are some fields that the user fills up. When the main fragment (the one that holds the viewpager) is closed (via a button click) i need to get the data from each recyclerview. How do i to that?
The best way to solve this problem is that implement interface which will give call back to activity holding these fragment and then from Activity pass it to fragment(main) and then use viewpager to get Fragment(secondry) and pass data.
Steps one would be implent interface which will give callback to activity and the get fragment from viewpager(Link for same)

Android pushing new activity on top of TabActivity and coming back

I have a question that I've been looking for answer to for several days with no luck.
So, to be as specific, I have TabActivity inside TabActivity and listview inside it (I call this entire screen "main screen"). That listview is populated from data sent from my database. Upon clicking an item of the listview, I start an activity but upon exiting that activity and coming back to the main screen, the listview is recreated and I was wondering whether there was a way to stop from being recreated.
Which method do I need to override to simply start and finish activity without destroying the main screen?
Edit--
I don't have FLAG_ACTIVITY_CLEAR_TOP attached to any of the activity

Using EditText in Activity Group

In my application i am using tabhost. And to control different activities i am using activity group. I have Activity A from which i am going to activity B. Activity B contains Edit Text, Spinner, Button etc. Now when i scroll the Activity B and press the device Back Button than it does not go to the previous Activity. It goes out of application.
Kindly suggest the answer.
This is the way the Activity lifecycle works for Activity Group. Try using fragments instead of activity group with your tabhost to get your movements. Also, please edit your question title to more accurately reflect the actual question.

Categories