It's becoming increasingly frustrating trying to get NetworkInfo working. I posted a question, but I guess people haven't seen it. Anyway, I really need a solution based on my flow below. I need to know when my network changes so I can determine what kind of network it is and then make decisions based off that answer. I thought, OK, maybe I'll try JobService, but I am not having a lot of luck trying to puzzle out how to use it for my needs. My app is reactive and happens all behind the scenes and only shows a notification when the user needs to do something. So, I guess I'm looking for direction. How to use JobService to get the granular information I need * and * to use to replace BroadcastReceiver for both Network Changes and Alarms. I'll need to be able to cancel/modify alarms as IPs change while people roam around.
Related
I'm looking to see if this problem is feasible. I want to create an Android app that allows a user to enable Do Not Disturb for every event in user-specified calendars. I've already looked into the AlarmManager class, and it does not seem to work for this purpose. A single AlarmManager instance would work for one half of one event (turning Do Not Disturb On). Another AlarmManager instance would be required to turn Do Not Disturb off. This would have to repeat for every event (which is variable) in the specified calendars. Is there an easier approach to this, or am I looking at this problem all wrong? I know that this has been done in stock Android, but it only works for one calendar at a time. If there is a better solution to this, could you point me toward the proper Android SDK classes? I do not need a code example. Thanks.
I developed a software in JAVA language for Windows that needs to check Firebase Realtime Database data changes by HTTP calls.
Now, i have a thing like that:
Timer timer = new Timer();
timer.schedule(new TimerTask()
{
public void run() {
checkNewValues();
}
}, 0, 500);
In CheckNewValues(); there's a normal HTTP get call.
My question is: is there a better way to do it? (there's a better way to do it for sure I think) I mean, in Firebase SDK we can set Listeners and use the OnDataChange but I don't have any idea how to simplify the whole process here without SDK, so, is there a similar way to do it without SDK? would be nice any suggestion or help.
Thank you in advance, happy coding to everyone! :)
I'm not sure why you don't just use the Firebase Admin SDK, which is available for Java/JVM and which makes this type of work simple.
But if you insist on doing this with a Firebase SDK, the closest you can get to the same behavior is by calling the Firebase Realtime Database's REST Streaming API. Similar to the Firebase SDKs, this API immediately gives you the current data at a location, and then gives you updates as they occur on the server. This means you'll only have attach a listener to the correct REST endpoint once, and don't need to poll for changes.
Your question is opinion based and can be closed that's why.
What is "better way"?
Better from implementation time? Then your approach can be the best one.
Better from the performance point of view? Then you approach can be the worst one.
Better from the point of view of data transferred via network? In some cases (if database change not often) you approach can be bad, because you trigger unneeded calls, in other (if database changes much more often than your code checks it), your approach can be good.
Etc. There can be many other reasons to consider it good or bad.
What should you do? Create a list of quality aspects (time, cost, performance, etc.), decide how important is each them in your particular case. Then you will see how good is your approach compared to others.
Here is the deal:
I want to make a Live Display feature, for my ElePhone p8000. I know there is Live Display feature already implemented, but its not working. Instead of that it has an app called MiraVision in which you can manually set modes. Like, when outside is bright u set the mode to outside, and u can clearly see everything on the display. In evenings u have to manually set it (again), on night mode, so it doesn't hurt your eyes.
Anyways, I want to build an APP that will have an option for LiveDisplay ON/OFF. When it's on, it will keep record of the clock, so when its day the brightness will be high, and when its night it will go dark, and change modes in the MiraVision app respectively.
I have experience in C++, C# programming, and a little bit in Java. So first of all I want to know is this possible? (i think it definitely is), and if you can give me any kind of help (tutorials, posts..whatever you think its helpful)
Thanks!
I am creating an app that checks for user locations every half an hour and updates the location of the user in the local database and then runs CRUD queries based on the user's location even when the app is not running. How do i do it ?
I have referred to this http://techtej.blogspot.com.es/2011/03/android-thread-constructspart-4.html article and i am still confused about which is the correct approach for my result ?
There are 4 options according to the article for what i intend to achieve according to me
1) Service : But since i feel it would be a long operation with the local database, i feel i should ignore this one.
2) IntentService : This cannot perform multiple tasks, so i feel this one also should be avoided for me as i have to get the location of the user and scan the database , update the database (3 tasks)
3)Thread : I am not sure how to call this when the app is not open
4) AsyncTask : I am not sure how to call this when the app is not open.
Basically i looking for something like a CRON JOB that runs on a local database while working on the location data.
It would be great if you could link me up to some tutorials and answer with a simple example to make me understand the difference of all 4 methods.
// editted on 16 March :
I have read something about a JobScheduler which is introduced in the API 21, but not sure if it also supports till Gingerbread and is it the right approach for my question
Thanx
When recording the users position use a service with a notification. Just for the sake of creating a morally responsible app that informs the user the app is tracking them. The service by definition runs in the background.
A fused location provider with setinterval(long) 30 minutes gets the interval. Set fastestInterval() to a minute to receive GPS data when other apps are using the GPS.
Have you considered using a SyncAdapter. Its best to schedule jobs at fixed interval and also optimized for battery usage. Also, once started, it can run independently of the app. As per your requirements, I believe this is best suited for your need. You can read about this here. This also removes the corner case of starting the service (generally used) when your device is restarted. Your app will still continue running the scheduled job even if the device gets restarted.
In the SyncAdapter you have to use a ContentProvider so wrap your DB inside a ContentProvider. Also, preferably use a CursorLoader to run longrunning tasks on DB. You should read about CursorLoader. This is a great way to access your resources. Also, you can define an Observer Design Pattern which Observes for changes in a DB and will perform a task when changes are made in DB. This can also be used inside your application itself and also inside SyncAdapter. Cursor Loader is best preferred for background work on DB. You can perform all CRUD Operations using a CursorLoader and ContentProvider.
This cannot perform multiple tasks
Yes, it can. It has only one thread, and so it can only do one simultaneous task.
i have to get the location of the user and scan the database , update the database (3 tasks)
I have no idea why you think that is three tasks. You cannot do them simultaneously.
Your bigger problem with IntentService is that getting location data is asynchronous, and IntentService is not well-suited for calling APIs that themselves are asynchronous.
But since i feel it would be a long operation with the local database, i feel i should ignore this one.
The point behind any service is for "a long operation".
Basically i looking for something like a CRON JOB that runs on a local database while working on the location data
Use AlarmManager to trigger a WakefulBroadcastReceiver, which then triggers a Service. The Service, in onStartCommand(), forks a background thread to (asynchronously) retrieve the location and update the database. The Service can then call completeWakefulIntent() on WakefulBroadcastReceiver, plus stopSelf() with the startId received in onStartCommand() for this work, plus allow the thread to terminate. If no other commands were received in the interim, the service will shut down.
I think you are looking for something similar to WakefulIntentService. This handles all your cases completely.
You can do your location and db related work inside doWakefulWork() of said implementation.
I've done what you are looking for, both with GPS and non-GPS.
The project I took as staring point for the non-GPS solution already does all you need, and is battery-friendly (credits should go to Kenton Price):
https://code.google.com/p/little-fluffy-location-library/
Take a look at it, it works like a charm. Just run it in any device. If you need any help customizing just let me know.
Just edit the "onReceive" method in the "TestBroadcastReceiver" to update your DB.
If you need the GPS solution let me know too, but I dropped it for being a battery killer!
Hope it helps.
1. I think for this requirement, Thread and inside it AsyncTask -- this structure will be useful.
In link provided by you, it is mentioned very nicely here
2. For location related blog, you can check useful materials here :
(1) Difference between Google Map Distance and Directions API
(2) Check this answer also
Hope this will help you
I'm falling into a bit of a dilemma. As I learn more and more about Android and Java, the more confused I am about the state of the building blocks of Android apps. (i.e. Activity, Service, Broadcast Recievers, Content Providers)
Since all of those building blocks are just Java classes, it's tough for me to wrap my head around them because there can be multiple instances of them. As of late the biggest challenge is with tracking which instance of the Activity is actually being created, started, resumed, etc;. I started playing around with Intent flags, and that just threw another wrench (or ten) into the equation.
Being able to tell their state would be indispensable and even better would be to see the current task stack/process id that the activity is associated with. At this point I'm just guessing whether or not FLAG_ACTIVITY_NEW_TASK, FLAG_ACTIVITY_CLEAR_TOP and FLAG_ACTIVITY_SINGLE_TOP are working properly.
Surely there is a solution. Is there any debugging tool that I can use to get an inside view of my app/process to see which components (specifically Activities) are in existence?
Some notes/thoughts I've had:
Should I create a unique static auto-increment int for each class to try and track it myself?
Is this what I want Get current visible activity to user?
Does this application manually keep track or is it really peaking inside of the process? https://play.google.com/store/apps/details?id=com.novoda.demos.activitylaunchmode
There has to be a debugging tool for this... -__-
Not sure if this will solve your understanding of the topic completely, but these guys did a nice app to try and visually see the main launch modes available for Activities > https://play.google.com/store/apps/details?id=com.novoda.demos.activitylaunchmode&hl=en_GB
Hope this helps in some way to explain things! :-)