Android - Maintaining webview state across activities - android

I've read multiple similar posts but have not found a working solution for this problem.
I have two activities A and B. Activity B is launched from Activity A (when I click a button in Acitvity A). Activity B loads a url which displays a map.
The problem is that, when I navigate away from Activity B and come back to it, the webview loads the URL again. Is there way to kind of maintain the state of the webview as is so that it does not load the url again.. I've seen posts hinting at onSaveInstanceState but I havent been successful getting this work.
Can someone please post some psedo/sample code?
Thanks in advance!

I've solved this problem using Fragments: Fragments Show/Hide
I could not find a way to maintain the state of webview (so that it does not requery the url) when I navigate away from a webview to another activity and navigate back to the webview - It alway reloads the url.
I found the fragment approach much better. Fragments was introduced in Android Honeycomb but for earlier versions you can you the support package : Comatibility Package

Related

Navigation Component "Back" via device reloads Fragment

The two screens relevant to my issue amount to MainFragment (a master view) and ProfileFragment (a detail view). The launch path from login -> main -> profile works fine. The return path isn't working as well. I get stranded at main when navigating backward with via gesture or device button.
On the initial "back" from the profile, I'm returned to main and see main's onViewCreated, onResume lifecycles. I expect back from main would return to login or even exit the app, but instead it reloads main a dozen times before crashing.
For any subsequent "back" from main, the logs reveal main's onAttach, onCreate, onViewCreated, onResume lifecycles recurring each time. This seems suspicious although it's a pretty vanilla navigation graph, a single Activity hosting four basic Fragments. They're all navigated with basic actions using their generated, type-safe Directions classes. I haven't overridden onBackPressed in any of these classes.
Combinations of app:popUpTo="#+id/loginFragment" and/or app:popUpToInclusive="true" haven't helped.
Do I need to implement back or "up" in order to work as expected? Any thoughts are appreciated.
On closer inspection, it's working the way it's coded. Of course it is!
The preceding LoginFragment checks a SharedPreference value and navigates to main. I confirmed that happens so quickly I thought I never returned to login screen, when in fact I did.
I'll investigate removing login screen from the stack after authentication.

Android open activity from fragment showing two screen separately

I have created an app. which contains MainActivity->inside fragments class loading with some UI works..
After I have tried to pass some datas to new Library Activity (inside one fragment available with make some works and need to get back result.)
Problem: when i open new activity, its showing two separate apps like..
starting Activity Page and Library Activity.. But, after entered library activity, finish the work and get back result to MainActivity Successfully..
Note: Even, Library Activity showing as a seperate App. thats my problem.
Please help..Thanks for Advance

StartActivity doesnt work after process is killed

I got a little problem with my app and I hope you could help me.
I developed an android app which contains an activity with fragment container which by default contains a pageviewer and through a navigation bar you can populate some more fragments.
In each of the fragments there are items, and when you click them they start a new activity.
Everything is working great until I drive my app into a state that the android OS kills its process for other apps, as described in the picture :
After I return to the app the listview is working fine, however when I click an item the new activity doesnt start, and the application just stays on the same page and for some reason OnResume() is called.
I check with debug messages and the OnClick function is working and the intent looks exactly like before the process kill.
Moreover, if I navigate to a new fragment everything is working fine.
Hope someone has the answer,
Thanks

Launching deep level activity

I have a main activity where user provides an input according to which i jump to a activity deep inside the heirarchy eg:
Let activities be B->C->D->E
On user input it will jump from A to E.What i want to do is i want to add B C D onto the backstack so that when user press back button it navigate according to the heirarchy. Also i want to remove A from the backstack so after B app should exit. I know there are many related questions but I am not able to make out how exactly to do this. I have been following the tutorial for providing proper back navigation on android official site:Create Back Stack. In this tutorial i did not understand how PendingIntent is used or what upIntent is.I am new to android development so any help will be appreciated.ThankYou
Sounds like you need to use fragments within 1 activities framelayout. You can use FragmentManager to manage the backstack
more info:
http://developer.android.com/reference/android/app/FragmentManager.html

Android Multi-Screen Application

How do you handle multiple screens in an android application? I have developed with the tab bar at the bottom without problem, however what I am wanting to do is replace all the content on the screen with the content from a new .xml layout file I have created in the project. Additionally, how would I tie the back end code to the new layout file? I'm sure this question probably exists already and is googleable (may have made up a new word). However, I don't know exactly what it is that I am looking for. Thanks in advance for your help.
What you need to do is, create a new Activity and add it to the AndroidManifest.xml:
<activity android:name="ActivityClassName" android:label="Label for the Activity"></activity>
and can be called in a method:
public void startActivity() {
Intent someName = new Intent(CurrentClass.this, ActivityClassName.class);
startActivity(someName);
}
Android applications generally use a separate Activity for each screen, and switch between them using Activity.startActivity and Activity.startActivityForResult. You can pass arbitrary data to an Activity via Intent.putExtra.
Hope this helps,
Phil Lello
It really depends on how you want your application to flow.
Let's consider the scenario where a user does the following:
Starts your first activity
Presses the 2nd tab
Presses the 3rd tab
Presses the back button
If you use a separate activity for each screen, then the following would happen
Activity 1 is started
Activity 2 is started
Activity 3 is started
Activity 3 is closed, user returns to Activity 2
(in this case pressing the back button again would you take you back to Activity 1, and pressing it again would exit your application)
If you used one activity for all the tabs, then the following would occur
Activity 1 is started
Activity 1 sets tab content to tab 2 content
Activity 1 sets tab content to tab 3 content
Activity 1 is closed, user returns to home screen
If you are using a screen with tabs, then the second method (a single Activity with a TabHost or similar) is the preferred method, otherwise the user will end up making a large activity-stack just switching between tabs (meaning if they switch between tabs a lot they'll have to press the back button a lot of times to exit).
If you want to go for the single activity approach, then do some research on TabHost and TabContentFactory. In the createTabContent method of your factory you can inflate a View/layout from XML to set as the tab content using View.inflate. Look those up and come back ask another question if you get stuck ;)
i think you may want to play with more than one activity.... you can have multiple activities and one xml for each of them... in this way you can have different screens... check these links. Multiple Activities, Creating an Activity.... hope this helps...

Categories

Resources