Starting the app when a if statement is fulfilled - android

I wanna design an app that works in the background and fetches JSON data from an URL and if data was something specific app starts itself automatically.
I don't have any code because I searched around and found nothing.
is this even possible? and how should I proceed if yes?

From android 10 you are not allowed to do that.
They introduced a background process limit which restricts activities and services to be started only if there is an already running instance in the background.
https://developer.android.com/guide/components/activities/background-starts
Also see this for further info: https://stackoverflow.com/a/59421118/6694770

You can recreate your activity:
finish();
startActivity(getIntent());

Related

what kind of background-service to use for background request and saving

i am currently trying to get code running as a background service.
what this code does is:
send request to server with current location of the user
receive response
parse response
save into model (singleton)
and this is set to happen in a 30 sec interval again and again.
now if my app stays in the background for too long, it will get disposed by the device and that code will not be executed anymore. what would be the right kind of background service for this usecase?
one of my main concernes is that i save my data in a singleton. but if my app is disposed this singleton will probably not exist anymore.
intent service doesnt make sense imho because it runs a one time tasks and has to be restarted from an app that might already be disposed at that point.
using the alarm manager would mean that i will have to save everything out of the app (sqllite for example) and then retrieve that data when the activity is started again which sounds rather complicated.
can someone please help me out here?
thanks in advance!
You sir needs the service of GCM
https://developers.google.com/cloud-messaging/
Thats exactly what you need for your desire ;)
But it's not less complicated as sticking to background services.
Also you can do a Hack: having two services watching your service to keep on running and itself...I swear when the User doesn't stop your app manually in the menu the System won't be able to stop them itself. Foolproof.

What will happen when my application swipe( killed) from list of recent applications?

My application is receiving calls(using CsipSimple) it's working fine,
But my problem is when i am getting call, On that time, am killing the
application from list of recent applications.calling notification also killing(Not showing).
What will Happen when swiping the app from recent applications?
is there any override method to be invoked?
What is the behavior of 'SERVICE' Component?
All objects going to be null?
Please guide me, Your help will be appreciated.Thank you in advance.
When your app is killed by that method, it is force Garbage Collected, so every value that wasn't stored in a Db or in Shared Preferences or some form of storing data would be deleted with no chance of recovery. If you want your app to perhaps restart in the background to do background processes when it is killed, you would need to add a Service that would do minor things like send little data here and there, if you hug too much resources even with a service, Android now does a good job of cutting you off completely. And I heard there could possibly be a feature that sorts of blacklists you.
This tutorial does a good job of explicitly explaining the Service type.
http://www.vogella.com/tutorials/AndroidServices/article.html
try using no. 5 in the Table of Content of the tutorial.
Android gives a guide on what to do and what not to do when using a service with this https://developer.android.com/training/best-background.html
And this is a more specific Tutorial with explicit details on doing downloads from
http://javatechig.com/android/creating-a-background-service-in-android

How do I get Android to dynamically refresh a url

I have used the Udacity Google Developing Android Apps tutorial and other sources to get my application to fetch an XML file in HTTP via an AsyncTask and display it via a ListAdapter.
Now I am trying to eliminate the refresh button and have it update when the app starts, and then at intervals afterwards.
As far as I can tell, even though the code at Udacity creates a Service, it doesn't eliminate the refresh button.
The code at http://www.vogella.com/tutorials/AndroidServices/article.html#exercise_bindlocalservice only refreshes when the list is clicked.
Does anyone have sample code where the list auto refreshes?
yourListAdapter.notifyDataSetChanged();
or you can use activity life cycle to update the activity through onResume() or onStart() if needed! but i guess you are looking for the first answer to refresh ur listAdapter
if your auto means the content will update whenever there are new contents. You should check those new content by yourself , the classical way is set a Timer to check it . After you got the new content , you can use them to update the view .
Update:
See this:http://www.vogella.com/tutorials/AndroidTaskScheduling/article.html
The reason for not using Timer is not because Timer does 'bad things' but Android does, All running task or data will be stopped and recycled by Android's GC at anytime , so the Timer will be terminated at anytime.
If you have a service or an activity in your application which should perform a repetitive task you cannot reply on a TimerTask or similar approaches and control it from your Android component. Activities and services can be terminated at any point in time by the Android system to free up resources.
So , you can rely on AlarmManager or JobScheduler in the tutorials I post above.
All my questions were answered by using the BasicSyncAdapter example from Google.

Is there any equivalent of Services of Android in iOS?

I want to check the database in my app every 12 hrs for rows with date column having corresponding date. This is accomplished by writing service in android. But is there any equivalent of services in iOS so that my requirement can be accomplished?
No. There is no such thing in the SDK or in iPhone/iPad in general. You can only write code that will affect the eco system of the app, not the operating system.
When your app is closed it's closed and no action will be taken until the user opens it/opens a push notification related to your app.
If the user approved location based services for your app, there are a few ways to run short background process even if your app is totally closed. One of them is by using Monitoring Shape-Based Regions which basically means if the user left region X/entered region Y
open the app and run a few commands before closing it again.
The clever way (and the only way I can think of) to accomplish what you're after in iOS is to run that service on a server and pull the data from the server when the app is opened.
In iOS7 and later you can use background fetch for this task.
You can check this tutorial:
http://code.tutsplus.com/tutorials/ios-7-sdk-working-with-background-fetch--mobile-20520
iOS Background work
Nowadays you you are able to use Background fetch or Background Processing Task or URLSessionDownload/UploadTask for doing something when app is in background more
[Xcode Background Modes]
[Background session]
You can find the solution here. Background Execution does this.
http://developer.apple.com/library/ios/#documentation/iphone/conceptual/iphoneosprogrammingguide/ManagingYourApplicationsFlow/ManagingYourApplicationsFlow.html
Added: Apple does not allow apps to run in background for all the time. It provides some finite-length time to complete your app execution. You can increase that time depending on your execution need. But that is not recommended.

Updating the app at exactly midnight

Is there a way to cause my app to update itself at exactly midnight every night? I need the new content to be displayed on the app right when it hits midnight. I have an idea of how to accomplish this, but if it isn't in another thread and is in the onCreate and the app is running in the background next time it is opened it would just display the previous info and not the updated?
I could also use help accomplishing this same thing with iPhone as well.
I will clarify a bit. So all the information that is to be displayed on the app will be in the app already. I simply want the content (whats displayed) on the app to randomize and then display the new group of content only once per 24hours or at exactly midnight. Hope that makes it more clear.
Android:
You can set pre-determined times to update with AlarmManager
You can look at a snippet here: Android: How to use AlarmManager
iPhone:
With iPhone you probably have to download the content whenever you re-open the app.
Can't you just have the app update the content upon launch, or when entering the foreground in the appDelegate.
This question is very vague - but if I understand the requirements correctly you will need to serve the application's content dynamically via a content server (or some type of a CDN). In this case there could be various scenarios.
In the easiest possible implementation, you could have the application be powered by data (XML, JSON, etc...) from something like Amazon S3 and have logic within the application to know how to fetch the correct data depending on the current day.
This wouldn't be extremely difficult to implement, but it would require building some type of cross-platform framework that reads the same kind of data for each application.
Is the content available before midnight?
If so, can't you have the app download it in the background beforehand and then make it available exactly at midnight?
If not, there's surely going to be some delay anyway.
app can not update itself at least in iOS apps.

Categories

Resources