Im wondering if there is a way in android to run tasks in the background by just using the android packages without using AsyncTask. What i imagine is a background task which is still running when the Activity is already finished or the app already got closed. I want the user to see the progress of this task in the notification tab of android (the tab you can swipe down from the top of the android screen).
I want to do this for example when i send e-mails or when i send data like images to the server. because they are quite long running tasks i dont want the user to wait for them to finish. i want them to run in the background so that the user can close the app. and i want the user to see the progress in the notification bar.
Also i would like to know if there is a way to automatically repeat such a background task when it failed because the device did not have connection to the internet.
Im looking forward to read the answers and to learn something new.
You must use service.
I think these links can help you to use it:
http://developer.android.com/training/run-background-service/index.html
http://inchoo.net/dev-talk/android-development/android-simple-service/
Download a file with Android, and showing the progress in a ProgressDialog
Example: Communication between Activity and Service using Messaging
Related
I was looking online for the best solution but couldn't find exactly what I wanted.
So, I am developing an app using React Native, and trying to make it so that even when the app is closed, once an hour a background task (which will do some fetching) will run, and at the end of it a notification (not a push notification) with a custom message will show up.
How can I achieve that?
Thank you upfront.
For Android you can use Headless JS which ships with RN. For iOS you'll need a package like react-native-background-task, which works with both. Android only projects you're probably better off just sticking with Headless.
You'll need react-native-background-task to perform the task you wish like fetching every hour, and then using some notifications library(i prefer firebase), you can show the notification to the user screen.
Also in firebase there is scheduling-notifications with which you can schedule notification showing on the screen (maybe you find a use case needing it).
I am working on a cordova android app.
My Question is:
is it possible to run a part of my app in background, so that the user can continue his work while sending data to server in background.
i dont want my user to wait while i sync my local database with remote database.
I dont want my whole application to go background. I want only the sync process to work in background.The total sync process is taking 3 Minutes time to complete. currently i am showing a popup with message Sync is in progress which forces the user to wait for completion. Now i want the sync process to work in background without disturbing the user.
i used https://github.com/katzer/cordova-plugin-background-mode but this is working when my whole application is going in background. If there is a way to solve my problem using this plugin please post here.
Thanks in advance
I am developing an app as follows:
Android APP (As a client)..it will send data to a Server (Java application running on a PC).
I implemented this using socket programming and it is working. I have following issues:
When I click the send button on my app the APP UI freezes for ~7 seconds. It is able to ping and connect to server but during this time frame the UI freezes and if I click any other button on the app I get a message app is stuck (but the app comes back ok after ~ 7 seconds). What is the best way to resolve it.
Once data (strings) is received on the PC, I want to show it in the form of List Box UI so that user can select/double click on the specific string and a message box is open showing that that particular string is selected. What is the best way to develop this UI and how can it be invoked directly as soon as server receives the data from Client (android app) and this UI should show up.
Please let me know. All help is appreciated.
Place all your network-related code into a separate thread, or (easier) and AsyncTask. Otherwise, you would block the UI, as you have noticed, and the app would actually crash on newer Android versions (ICS and JB).
If you search SO and the interwebs, you will find plenty of examples.
I'm writing an android app just to get familiar with the OS and API. I'd like to show what my app is doing to the user in a seperate screen and not via notifications. The reason is that I'd like to show the user exactly what the app is querying and how long it took etc. I saw an example of this in the superuser app which shows what the app is doing when it is updating itself.
Is there a library to do this?
Is it as simple as just showing a text box and then populating it programatically?
I would have done it so..
Just push state changes to your UI thread and display them there.
You can do that via BroadcastReceiver, which is intended to let background services communicate with UI activities, or LocalBroadcastManager which is simpler version of the previous.
Here on StackOverflow you will find dozens of questions describing how to implement it.
I currently have a program where a user fills information out and sends it to a server. It then downloads a one to two MB file to device. I have it setup so the phone does not sleep when it is downloading the file, but it is interrupted when the user manually presses the sleep button or a text comes in to the phone. What would be the best solution to this? Should I create a service or is there someway to tell the activity to keep downloading in the onPause method?
won't it be better to download in the background using an android service and posting an android notification when it will be done?