Go Back   Android Forums > Android Development > Application Development
Application Development Dev lounge for our application developers.

Get excited for the Samsung Galaxy S5! Find everything you need and discuss it in our Galaxy S5 Forum!

test: Reply
 
LinkBack Thread Tools
Old July 16th, 2013, 11:33 AM   #1 (permalink)
Junior Member
Thread Author (OP)
 
Join Date: Jan 2013
Posts: 53
 
Device(s):
Carrier: Not Provided

Thanks: 11
Thanked 1 Time in 1 Post
Default if my app needs to sound an alarm ,will it stay on and stop other system stuff up

im making another app and i need it to sound an alarm at some point.
my question is will the app stay running all the time and will if affect the system or not?

how do minmize the use of resources or is that best or possible?

thank all

flyhigh427 is offline  
Reply With Quote
sponsored links
Old July 20th, 2013, 05:38 PM   #2 (permalink)
Junior Member
 
Join Date: Jul 2013
Location: Michigan
Posts: 30
 
Device(s): N1, N Galaxy, N4, Samsung S4
Carrier: T-Mobile

Thanks: 0
Thanked 8 Times in 7 Posts
Default

The AlarmManager that you're going to use won't consume much resources. All you have to do is to create a broadcast receiver and register it in the Manifest file. E.g.


<receiver android:name="com.example.YourAlarmReceiver">
<intent-filter>
<action android:name="com.example.yourAlarmActionName" />
</intent-filter>
</receiver>

And in your code, find some place to create the alarm (the example shows trigger an alarm after 1 minute:

PendingIntent pi = PendingIntent.getBroadcast(YourContext, 0,
intent, PendingIntent.FLAG_UPDATE_CURRENT);

AlarmManager am = (AlarmManager) getSystemService( Context.ALARM_SERVICE );
am.set(AlarmManager.RTC_WAKEUP, new Date().getTime + 60 * 1000, pi);
Armuro is offline  
Reply With Quote
The Following User Says Thank You to Armuro For This Useful Post:
flyhigh427 (July 20th, 2013)
Old July 20th, 2013, 08:19 PM   #3 (permalink)
Junior Member
Thread Author (OP)
 
Join Date: Jan 2013
Posts: 53
 
Device(s):
Carrier: Not Provided

Thanks: 11
Thanked 1 Time in 1 Post
Default

hey and thank you
i was thinking i would use it to start an
Activity every morning to check input from my app
everyday
i guess i can start an Activity in the app or will i have to start the whole app?
flyhigh427 is offline  
Reply With Quote
Old July 20th, 2013, 09:58 PM   #4 (permalink)
Junior Member
Thread Author (OP)
 
Join Date: Jan 2013
Posts: 53
 
Device(s):
Carrier: Not Provided

Thanks: 11
Thanked 1 Time in 1 Post
Default

worked like a charm
thanks
flyhigh427 is offline  
Reply With Quote
Old July 21st, 2013, 03:10 PM   #5 (permalink)
Junior Member
Thread Author (OP)
 
Join Date: Jan 2013
Posts: 53
 
Device(s):
Carrier: Not Provided

Thanks: 11
Thanked 1 Time in 1 Post
Default

i call this activity from the main activity and the reboot activity..
it works but i was wondering does it look alright or is there a better way?
thanks









Code:

public
class alarmsetter_activity extends Activity{ @Override
protectedvoid onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Intent myIntent = new Intent(getBaseContext(), myreceiver.class); myIntent.setAction("com.try1.pratice1.ACTION"); PendingIntent pendingIntent = PendingIntent.getBroadcast(getBaseContext(), 0, myIntent, 0); AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE); Calendar calendar = Calendar.getInstance(); //calendar.setTimeInMillis(System.currentTimeMillis());
//calendar.set(Calendar.DAY_OF_MONTH, 22);
calendar.set(Calendar.
HOUR_OF_DAY,7); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.AM_PM, Calendar.AM); if (calendar.getTimeInMillis()<System.currentTimeMillis()) { calendar.add(Calendar.DAY_OF_YEAR, 1); } alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent); finish(); } }  
flyhigh427 is offline  
Reply With Quote
Old July 21st, 2013, 05:37 PM   #6 (permalink)
Junior Member
 
Join Date: Jul 2013
Location: Michigan
Posts: 30
 
Device(s): N1, N Galaxy, N4, Samsung S4
Carrier: T-Mobile

Thanks: 0
Thanked 8 Times in 7 Posts
Default

Basically your method looks fine to me. Two more comments:

You can use cal.roll(Calendar.DAY_OF_MONTH, 1) instead of the add() method.

If you use HOUR_OF_DAY, you're using the 24HR format, so you don't need to set AM/PM.
Armuro is offline  
Reply With Quote
The Following User Says Thank You to Armuro For This Useful Post:
flyhigh427 (July 21st, 2013)
Reply


Go Back   Android Forums > Android Development > Application Development
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 06:58 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.