Resend my activation email : Register : Log in 
BCF: Bike Chat Forums


Android coders?

Reply to topic
Bike Chat Forums Index -> The Geek Zone
View previous topic : View next topic  
Author Message

Gazdaman
I did a trackday!!!



Joined: 12 Aug 2004
Karma :

PostPosted: 16:09 - 03 Feb 2011    Post subject: Android coders? Reply with quote

So I want to write an app that is based around an alarm, so I've started writing the basics, and I can't see why this code won't work.

It sets an alarm through AlarmManager.set(), and sets it for 5 seconds after it's set.

It pops up the Toast to confirm the alarm's been set. But it doesn't appear to run the method that is the alarm 'going off'.

Anyone spot any errors?

Code:

package com.example.AlarmTest;

import android.app.Activity;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;

public class AlarmTest extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
        AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
       
        Intent intent = new Intent(this, OnetimeAlarmReceiver.class);
        PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0);
 
        alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + (5 * 1000), pendingIntent);
        Toast.makeText(this, "Alarm set", Toast.LENGTH_LONG).show();
       
    }
   
    public class OnetimeAlarmReceiver extends BroadcastReceiver {

       @Override
       public void onReceive(Context context, Intent intent) {
       Toast.makeText(context, "Alarm worked.", Toast.LENGTH_LONG).show();
       }
       }

}


Karma for any help!

Gaz
 Back to top
View user's profile Send private message Send e-mail Visit poster's website You must be logged in to rate posts

Frost
World Chat Champion



Joined: 26 May 2004
Karma :

PostPosted: 17:05 - 03 Feb 2011    Post subject: Reply with quote

No expirence with droid, but when ever i've done anything with timers and callbacks i've always found unexpected behaviour was due to threads, or lack of.
 Back to top
View user's profile Send private message Send e-mail You must be logged in to rate posts
Old Thread Alert!

The last post was made 15 years, 227 days ago. Instead of replying here, would creating a new thread be more useful?
  Display posts from previous:   
This page may contain affiliate links, which means we may earn a small commission if a visitor clicks through and makes a purchase. By clicking on an affiliate link, you accept that third-party cookies will be set.

Post new topic   Reply to topic    Bike Chat Forums Index -> The Geek Zone All times are GMT + 1 Hour
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Read the Terms of Use! - Powered by phpBB © phpBB Group
 

Debug Mode: ON - Server: birks (www) - Page Generation Time: 0.08 Sec - Server Load: 1.18 - MySQL Queries: 13 - Page Size: 33.65 Kb