سؤال

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.

هل كانت مفيدة؟

المحلول

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.

نصائح أخرى

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

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top