Know when app data from Application Manager is deleted - java

I need to have an event that is called at the moment when the user of the phone has clicked 'Clear Data' in the 'Application Manager'. Is there a way to do that?
I need to know that because I got a database that holds very important information and I need to know when that information is deleted. I tried to look for database events for that and even events for data deletion with no luck.

There is no such event.
The first opportunity to detect this is when your app is started next.
(If you're using SQLiteOpenHelper, your onCreate method will get called.)
However, there is no guarantee that the user will actually use your app again.

Related

How to release information stored in database after pausing activity for some time?

I'm building my Messenger app. There's table called "Loaded" in MySQL server, which basically stores a pair of VARCHAR: Who_requested - Who_loaded. It means that the user named "Who_requested" has loaded user named "Who_loaded" into their main chat page. So when "the main user" scrolls down to see more users below their chat page, the server will know what to load next (I'm implementing pagination in RecyclerView). It looks something like this:
The thing when user stops the app, I'd like to wait for like 15 minutes before releasing all information related to "the main user" in loaded table and restart the app (like the effects that you might notice in Youtube after putting Youtube in the background for a while). How to implement this?
Some methods are
One
The obvious way is to have a task/service running that prunes the out of date entries. The disadvantage is that this could die and never run again. So you have to have some way of restarting it.
Two
If you don't want to do the above, then another method is to use a trigger.
Have an AfterInsert Trigger on the table
Delete out-of-date entries
The advantage is that you don't need another task that could fail. The disadvantage is that if there are no new entries, then the table does not get pruned.
Three
When you fetch the entries to display/action, only fetch the ones that are newer than 15 minutes. This doesn't prune them, but everything works fine. And you use a task or trigger to delete them.

Inserting The UID into Firebase Database Only once

In the main activity of Android Studio, immediately after anonymously signing in into firebase, I have this line of code:
FirebaseDatabase.getInstance().getReference().child("Online Users").push().setValue(currentUser.getUid().toString());
So, the UID of current user will be saved into firebase under the child "Online Users". Good. Problem is, when I open the app for the second or third time, or if I navigate from another activity to the main activity, this line of code gets executed again, and now I have several identical entries in the firebase. I mean, one UID has been pushed into firebase several times. But I don't want that. I want only one copy of each UID there. How can I achieve that?
Whenever you want a specific value to be unique in the Firebase Database, model it as the key of a list.
In your case that means that instead of calling push() you actually use the UID as the key:
FirebaseDatabase.getInstance().getReference().child("Online Users").child(currentUser.getUid().toString()).setValue(true);
Now whenever the user comes online again, they're just writing true to the same location again.
Note that the same user can come online from multiple devices. If you are trying to build a presence system, tracking what users are online, I recommend studying the sample presence system in the Firebase documentation which handles the edge cases correctly.

Exchange Calendar, creating appointments and unique ids

I am using ews-java-api and having a lot of problems
I create appointments and also listen for appointments created elsewhere.
My problem is I create the appointment with
new Appointment(exchangeService).save(notificationMode)
I also save the appointment details including uniqueId, lets call it x, to my db
I see the appointment appear in exchange no problem, I then see a notification that it has been autoaccepted (I can turn off auto accept for the room and still get the same problem below.
Then I see my exchange subscriber kick off as it receives the notification events from exchange that a new appointment has been created. I seem to get 4 events each time, a created event, two modified events and move event.
The problem is each of these events have a uniqueId of y not x as I would expect.
This means that I cant check to see if this is an appointment I have already created.
I never get an event with the original uniqueId x as I would expect. I know that unique ids can change, and that sucks, but there does not seem to be any other field I can use.
Any ideas what I can do to work around / fix this?
A given id for an item will change when the active directory in which it resides changes. It sounds like your auto accept is moving the item. I have not tested this scenario.
If you do a simple .save() you will get a create and a modify event back from exchange on your next push/pull. There doesn't appear to be a way to prevent this. They should have the same id as the one that you got from your save. You just need to check to see if you already have the item for the create. For the modify, well I can't speak for Microsoft as to why we get a modify but it should be exactly the same as the create.
You are then getting a modify, and a move event when the item changed directories. These 2 items will have different ids than the one that you received during the original save. The ItemEvent has an oldItemId that I believe you can use. It's also possible to parse out the GUID from these ids which doesn't change but no real need to do that I think. Best approach might be to use the OldItemId and process the move event.

checking if any Calendar Event/ Media Files got updated

Am working on one of my requirement, halfway through am stuck on an issue. As per my requirement I need to know if any calendar event has been updated, say like any new participant is added or any event fields has been updated say Title,Description or location. As of now am able to know precisely if any event is added or deleted from system, but unfortunately am not able to detect out any update.
The same scenario goes to media, i need to know if any fields related to a media is changed, say name,title or parent folder/path etc.
to summaries my requirement is to know if any filed in Media or Calendar db is updated. to detect Insert or Delete am using Content Observers, as it only tells me something is changed by through onChange() call back, but it never tells you which rows was updated.
regards,
techfist
I had a similar problem with the browser. I made use of shared preferences.
When I read the DB, I know that I have read all the entries until the time stored in shared preferences. So each time I read DB, I need to check for all the changes after the time that was stored in shared preferences and update the time in the shared preferences to current time. For code and my implementation can can look to my solution in Android History Content Observer

Ensure that an object is stored in the database before the app is killed (Android)

I have an Integer[] in Android. I need to save it persistently in a table of my database but canĀ“t save it with each change because it changes constantly while the application is beeing used and I'll suppouse a high overhead.
I have decided that update the table once every 20 minutes is ok but I need to ensure that the last change is saved even if the user kills the app with a task killer at the minute 22 for example
How can I do it?
Thanks in advance
If your app is Force Closed, there's no way for you to run code from the dying app. But you could override the onPause method in Activity if you want to save your data when your app looses focus.

Categories