Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6641269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:47:27+00:00 2026-05-25T23:47:27+00:00

As mentioned in the question, and the following shows mu code .. AlarmActivity package

  • 0

As mentioned in the question, and the following shows mu code ..

AlarmActivity

package adham.test;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class AlarmActivity extends Activity {
    /** Called when the activity is first created. */
    Button btnStart,btnStop;
    Context context;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        btnStart=(Button)this.findViewById(R.id.btnStart);
        btnStop=(Button)this.findViewById(R.id.btnstop);
        context = this.getApplicationContext();

        startService(new Intent(context,AlarmService.class));


        btnStart.setOnClickListener(new OnClickListener(){

            @Override
            public void onClick(View arg0) {
                startService(new Intent(context,AlarmService.class));
            }

        }); 
        btnStop.setOnClickListener(new OnClickListener(){

            @Override
            public void onClick(View arg0) {
                stopService(new Intent(context,AlarmService.class));

            }

        });
    }
}

AlarmReceiver

package adham.test;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

public class AlarmReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context c, Intent i) {
        try{
            Bundle b = i.getExtras();
            String msg = b.getString("alarm_message");
            Log.d("Receiverr ---","now");
            Toast.makeText(c, msg, Toast.LENGTH_LONG).show();
        }catch(Exception e){

        }


    }

}

AlarmService

package adham.test;

import java.util.Calendar;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import android.widget.Toast;

public class AlarmService extends Service {
    private static final String TAG = "MyService";  
    Context c;
    @Override
    public IBinder onBind(Intent arg0) {
        // TODO Auto-generated method stub
        return null;
    }
    @Override   
    public void onCreate() {
        Toast.makeText(this, "My Service Created", Toast.LENGTH_LONG).show();
        c= this;

        }
    @Override
    public void onStart(Intent intent, int startid) {   
        Toast.makeText(this, "My Service Started", Toast.LENGTH_LONG).show();

        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.SECOND, 10);

        Intent i = new Intent(c,AlarmReceiver.class);
        i.putExtra("alarm_message", "Hello, Alarm is running !");
        PendingIntent pi= PendingIntent.getActivity(c, 19237, i, PendingIntent.FLAG_UPDATE_CURRENT);
        AlarmManager am = (AlarmManager)c.getSystemService(ALARM_SERVICE);

        am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), pi);

        }
    @Override
    public void onDestroy(){
        Toast.makeText(this, "My Service Destroyed", Toast.LENGTH_LONG).show();

    }


}

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="adham.test"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="9" />

    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".TestServicesActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <service android:name=".AlarmService"></service>
        <activity android:name=".AlarmActivity"></activity>
        <receiver  android:process=":remote" android:name=".AlarmReceiver"></receiver>
    </application>
</manifest>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T23:47:28+00:00Added an answer on May 25, 2026 at 11:47 pm

    I think you never raise any broadcast. Your code shows:

    Intent i = new Intent(c,AlarmReceiver.class);
    i.putExtra("alarm_message", "Hello, Alarm is running !");
    PendingIntent pi= PendingIntent.getActivity(c, 19237, i, PendingIntent.FLAG_UPDATE_CURRENT);
    

    You are calling getActivity but AlarmReceiver is a Broadcast, you need to call getBroadcast(...) instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following code is mentioned in this question . int (*my_printk)(const char *fmt, ...);
I have a question about the behaviour of my routes.rb . The following code
I have the following code: http://www.nomorepasting.com/getpaste.php?pasteid=22615 Which is called by the javascript mentioned in
As mentioned below I have made changes to the code which looks like following
I am trying to implement the same code that was mentioned in this question
So following on from this question: Erlang lists:index_of function? I have the following code
In my app I need to send SMS, so I use the following code
I was trying to answer the question mentioned here by passing the reference to
From the link ( which is mentioned in Question ) my question is that
EDIT: the script mentioned in the question, and the other script pointed among the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.