0

There are several packages in my application that user can select each one according to different prices. In server side I store some information of client such as device Id, Android Id and etc.

Based on the package that user choose, for example user has chosen 2 hours plan, server sends me Expire time and I store it in local database.

The question is what is the best way to check that is trial period expired? If user buy 2 hour plan at 12:00, therefore expire time will be at 14:00. I store 14:00 in database and each time application lunched, I check the data base. But the issue is if we assuming that user is using the application how to close application or prompt user that the plan has expired? How do I understand if time of handset is changed by user?

Is use of services best way? what things do you suggest?

============== Update:

The point that I forgot to say is, because of some restrictions in our office I have access just to three activities that I'm designing and I can't ask other developers who are working on this project, check this and check that or use this variable. But because I'm working on main activity, this activity is the only activity that has access to database.

tshepang
  • 12,111
  • 21
  • 91
  • 136
Hesam
  • 52,260
  • 74
  • 224
  • 365

2 Answers2

1

You should maintain a flag in the SharedPreference and if the flag is set you could show an expiry message instead of your normal activity. You could update the flag using AlarmManager once your period has expired.

Here are few tutorials on AlarmManager and SharedPreferences.

Arnab Chakraborty
  • 7,442
  • 9
  • 46
  • 69
  • Thanks dear Aki, I have updated above story. If I want to use SharedPreferences, I think in each activity I have to check it and due to above update, I have not access to all activities because my part of job is developing general framework and I can't ask in future please check this SharedPreferences. The things that I need, I want AlarmManager runs my mainActivity when time is up. Is it possible? – Hesam Dec 13 '11 at 09:14
  • If my answer doesn't solve your problem, why did you accept it? – Arnab Chakraborty Dec 13 '11 at 09:17
  • Your UI components will somehow have to be informed about about the expiry. even if you use a service which provides the expiry information, you will have to bind your activities to the service to fetch this information. – Arnab Chakraborty Dec 13 '11 at 09:19
  • My approach will work if you can atleast control the main activity from which other components of your application is invoked. If you could describe your design a little more, maybe I would be able to help. – Arnab Chakraborty Dec 13 '11 at 09:20
  • Thanks Aki, abut your question "If my answer doesn't solve your problem, why did you accept it?", The link of AlarmManager that you gave me was useful for me and I used Service to check expiry time. – Hesam Dec 14 '11 at 02:09
0

The easiest and best way to do this is the implement BackupSharedPreferences.

The preferences are preserved, even if the app is uninstalled and reinstalled.

Simply save the install date as a preference and you are good to go.

Here's the theory: http://developer.android.com/reference/android/app/backup/SharedPreferencesBackupHelper.html

Here's the example: Android SharedPreferences Backup Not Working

:) Pete

Community
  • 1
  • 1
pstorli
  • 127
  • 1
  • 6