I am developing a web page for android browser. The page will authenticate users. I placed an iframe that will refresh every 10 minutes to keep the user logging while the page is open. However if the user switch to another application placing the web browser in the background, the refresh to keep logged in stops. So when the user switch back to the browser the session is lost and errors pop up from my ajax call in that page.....
How could i handle this scenario when the browser is sent to the background and keep the session alive?
thanks
Your app will call the onPause() and then the onStop() method of your Activity when it loses focus.
If you want to make things work in the background, you will have to do this in a Service. There is just no better way of doing background tasks.
Related
For example I have native app and I open webview from my app. I need to keep my app alive because If my native app have no activity in 5 mins the session will be expire. So that I have to pass deep link to website So website can keep interval my native app deep link to make native app alive. The Question is How can I write the code to call deep link without reloading or re-direct website page ?
In short, no.
One option would be to (a) refactor the app to more gracefully handle expired sessions (e.g. sign in again) and (b) refactor server to allow new session to restore state of prior session.
Another option would be to change the server implementation so that sessions don’t expire so quickly.
And if you are opening a your web view from within your native app (as opposed to launching a web browser app), your app is actually still running, so there’s nothing to stop you from having some timer that fires off some task periodically to keep it alive from the server’s perspective.
But your answer does not rest within some sly use of deep links.
I'm working on Background Task using this link it's working in android when app in background state and terminate state but not in iOS.
Right now it's working only when user open the application.
But in my scenario after 5mins user will use the app or not, directly call Logout method and delete the data in both the states(Background&Terminate).
I am trying to create an app in which i am using background serviced plugin for uploading data to server.Then i tried to go back to the app home page when a background service will start so the user can do other work while data is uploaded. but the issue is as soon as I click on the device back button it gives an network not found error and background service stops and it navigate to another page. Then i search how to navigate to device main page using device back button using home plugin know after starting the background service when i click on the back button it opens the device home-screen and the backgroung process continues. Can anyone tell me how to make an background serviced continue and navigate to another page.
I'm working now in a project to download images from the web and then show it after completing its download.
i made an activity class that has a button and text field and when the user press on the button, i started a service which will show a notification in status bar and after download i will show a message .
my main problem now is i want to go to other application or home page while the download is working.
i tried it but i after the download i got the message ,,, " Force quit"
should i use broadcast receiver or remote server to handle what i want.
Thanks,
The service should be the one downloading the content. If you go to the home activity our activity calls onPause, stoping all the work in progress.
Activities are just that, activities, they only work when visible and are built strictly for user interaction or a user activity, so this is impossible. Use a service instead. Here is a diagram showing lifespan of an activity:
Link to App activity explanation on Android developer site
You may need to call Looper.Loop() in your service to keep it running if you have any listeners in your service.
In my application, I used a library that displays ads in my app. When a user clicks on the ad, it launches the Browser app, and the onClick events are handled by the library itself.
I also have a placed code in onPause() and onStart() methods that detects whether any of my Activities are sent to background (user pressed Home) or switching between any of my Activities.
So if the app is either freshly opened (no instance is running) or re-opened from background, it will display a dialog box. If the user is only switching from any of my Activites, then the dialog box shouldn't be displayed.
Now the problem is that when the user clicks on an Ad, the Browser app gets loaded and would mean that my App has been sent to background, and so when the user closes the Browser, it will still display the dialog box when it shouldn't.
Is it even possible for my App to determine the previously displayed external Activity (ie. Browser) and not display the dialog box?
Or are there better approaches that I can follow in implementing such setup?
Thanks in advance.
I don't think that there is a way for your Activity to know, which was the previous activity. A simple work-around is to save the time the dialog was displayed and not displayed it again, before some time passes. You can decide on the exact time period based on your application's requirements.
This may be in fact better in some situations. If the user switches from the Browser to your application and it has been some time he has used your application, it will be appropriate to show the dialog again.
you can use onResume() method to specify the behaviour when your activity get back from the background.