Webview fastest way to reopen - android

I have a webview activity that shows my interfaces, but I have to call another activity (non webview).
After the other activity has finished I have to go back to the webview one, but it takes too long to open as it recreates the activity in a intent.
Is there a way to keep the webview activity in the background and just reopen it once the other activity has finished? Any suggestions to make the webview at least load faster?

Related

webview reload to home page when switching between activities

hello im makeing a vwe browser app and it have a faw problem and dont know which part of the code i post
bookmark activity when i go to the bookmark activity it opens fine but when i switch back to the webview it reload to the homepage not the last page it was in PS it don't reloads when the screen change Orientation
its kind of slow
open videos like youtube but don't let them go full screen
ourview = (WebView) findViewById(R.id.webView1);
ourview.getSettings().setJavaScriptEnabled(true);
ourview.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
ourview.getSettings().setLoadWithOverviewMode(true);
ourview.getSettings().setSupportZoom(true);
ourview.getSettings().setBuiltInZoomControls(true);
ourview.getSettings().getAllowFileAccess();
ourview.getSettings().getAllowFileAccessFromFileURLs();
ourview.getSettings().getJavaScriptCanOpenWindowsAutomatically();
ourview.getSettings().setLoadsImagesAutomatically(true);
ourview.loadUrl("http://www.google.com");
Switching between different activities,will always call onCreate() method.
So since your ourview.loadUrl("http://www.google.com"); is in onCreate() method,
it is called each time when you switch between those activities.
That is why webView reload to homepage when switching between activities.

Android place activity on another activity

I have two activities in my app, FirstActivity and SecondActivity. FirstActivity accesses information from the internet so it takes a few seconds to load initially. I'd like to be able to open SecondActivity and then easily go back to FirstActivity without reloading it.
One of the thoughts I had on how best to accomplish this would be to open SecondActivity on top of FirstActivity, and then remove SecondActivity, when the user wishes to go back to FirstActivity. That way FirstActivity doesn't have to reload because it was loaded the whole time, merely hidden behind SecondActivity.
However I'm not really sure how to best accomplish this task. I couldn't figure out how to open an activity on top of another activity. Any help on how best to do this would be greatly appreciated, thanks!
FirstActivity accesses information from the internet so it takes a few seconds to load initially. I'd like to be able to open SecondActivity and then easily go back to FirstActivity without reloading it.
I recommend that you start with the 2nd activity directly, and from there you begin an async task to download whatever you need from the internet. When the async task is done, you simply switch to the first activity, which uses the things you downloaded. If you have few things to pass over, consider putting the downloaded info as an extra to the activity switch intent.
Alternatively, look into fragments:
http://developer.android.com/guide/components/fragments.html
Have your two current activities be two fragments. For the main activity, set the 2nd fragment as active at the start of the app. When the download is finished, switch to the 1st fragment.

How to force close an app

When my app crashes, it loads again in a random activity instead of being force closed.
When I call android.os.Process.killProcess(android.os.Process.myPid()) it follows that behaviour too.
I just want my app to force close if needed and let the user send me their reports.
What should I do to avoid that behaviour?
Are you sure it loads some random activity? Usually it loads the next activity on top of your app's activity stack.
from https://stackoverflow.com/a/7240460/262462:
start first activity (either splash screen, or whatever activity is currently at the bottom of the activity stack) with FLAG_ACTIVITY_CLEAR_TOP (which will quit all the other activities started after it, which means - all of them). Just make to have this activity in the activity stack (not finish it for some reason in advance).
call finish() on this activity

Display previous activity after launching browser activity?

I'm got a scenario where my app has a series of activities and then opens a Browser activity. The browser activity then authenticates the user and calls back to a URL with custom scheme i.e. myapp://finished.
An intent filter is used to trigger the display on one of the existing activities. I basically want the app to go back to the activity that was displayed before the Browser activity was launched.
The problem I'm having is that the Browser activity creates a new task so when the browser calls back and my activity is loaded a new instance of it is created in the browsers task and not my app's orignal task. This results in my activity being recreated.
Task (created by my app)
1) Activty 1
2) Activty 2
Task (created by the browser)
3) Browser Activity
4) Activity 2 (new instance)
I'm aware that there are flags that can be used to resume existing activities instead of recreating them but they don't work as any new intent that is created after the browser is restricted to the browsers task stack.
I guess by finishing the activity just after getting invoked by webview will pop up your last activity on the stack.
Are you using a Webview or launching a 3rd party browser? In the last case, consider using a Webview

Android: Recovery Activity When I press Home

i have the following question.
I have an activity which is showing a progress bar while a service is downloading data from an API.
I want that when i press Home and relaunch my program the activity and which is not the first activity called but it is in the stack was recovered in order to continue showing the progress.
I have read about the cycle of life of activities but i don't find a clear solution.
The same thing happens If i am in the activity which is showing the progress bar and i press a button that takes me to another activity, when i go back, can i recover the old activity instead launch one new?
Anyone helps me?
Thanks
The problem is that pressing the home button will erase the whole activity stack. That means there is no possibility to go back to the activity it even is not certain that the activity still exists.
If this a progress that is interesting for the user that it is still running you could display a notification bar icon until the progress is finished. I think you can specify a special intent for clicking on the notification bar and filter this intent with your activity. That way you would go back to the activity. But you still face the problem that the activity is saved and has no reference to the background thread doing the work.
If your Activity has left the stack its finish method is called. You shouldn't try to reuse this activity later on. The best way is to think of a way that the whole state of the activity can be saved and restored later on. To restore a reference to the background thread doing the work you could subclass the application class and save a reference to the running task in your subclass.

Categories

Resources