简体   繁体   中英

Android: Structure of alarm app

I am creating an alarm application. I currently have 2 activities, one called AddAlarm which creates a new alarm and allows users to enter data such as alarm time and title. The other activity is called Alarm and it displays all the alarms that are currently set in a ListView.

What I do not understand is:

1) How can I pass the data from the AddAlarm activity to a ListView item in the Alarm Activity?

2) How can I pass the data back to the AddAlarm activity when the user edits the alarm?

3) How can I store the data each alarm when the app restarts?

I have already tried to create a bundle for each alarm, however, I learned that these cannot be stored in SharedPreferences and I am not sure how bundles can be used in an arraylist.

Do you guys have any suggestions? Thanks a lot!

From your question, what is clearly understandable is that you are facing problems with data storage for your app.

You do not need to pass data from one Activity to the other, what you need to do is use a persistent storage mechanism, such as SQLite or Realm .

The idea is simple, I will list down some of the important points.

  • When the user adds new alarms from the AddAlarm activity, just store the data in the database
  • In the AlarmActivity with the ListView, make a query to find all the alarms which have not expired yet and show them
  • Whenever an alarm expires, make the necessary modifications to that particular alarm entry in the database so that it is not shown again

This would be an idea way to handle the scenario for your app. Please have a good read at this .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM