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 8123599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:13:50+00:00 2026-06-06T06:13:50+00:00

In my application I want to call service from Receiver. This is my NotificationReceiver.java

  • 0

In my application I want to call service from Receiver.

This is my NotificationReceiver.java

 public class NotificationReceiver extends BroadcastReceiver {

    NotificationReceiver _this = this;
    private static Context _context;
    public static final String ACTION_REFRESH_SCHEDULE_ALARM = "com.example.receiver.ACTION_REFRESH_SCHEDULE_ALARM";
    String SERVER_URL = "http://192.168.1.7:8080";

    @Override
    public void onReceive(final Context context, Intent intent) {
        _context = context;
        initClient();
        SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(_context);


        if (settings.getString("userId",null) != null){

            gotNotification(new ClientListener(){
                @Override
                public void onSuccess(String response) {
                    try {
                        JSONObject object = new JSONObject(response);

                        System.out.println("Service object = "+ object);


                    } catch (JSONException e) {
                        e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
                    }
                }
                @Override
                public void onFail(int error) {

                }
                @Override
                public void onCancel() {

                }

            },settings.getString("userId",null));
        }
    }

    private void initClient(){
        NotifierRestClient.init(SERVER_URL + "/api");
    }

    private void gotNotification (final ClientListener clientListener, final String uId) {
        new Thread() {
            @Override
            public void run() {
                try {
                    final String responseText = NotifierRestClient.getUserNotifications(uId,null);
                    if (clientListener != null) {
                        clientListener.onSuccess(responseText);
                    }
                } catch (final Exception e) {
                    e.printStackTrace();
                    if (clientListener != null) {
                        clientListener.onFail(505);
                    }
                }
            }
        }.start();
    }
}

And this is my NotifiactionService.java

public class NotificationService extends Service {

    private AlarmManager alarmManagerPositioning;
    private PendingIntent pendingIntent;

    @Override
    public void onCreate() {
        super.onCreate();

        alarmManagerPositioning = (AlarmManager) getSystemService(Context.ALARM_SERVICE);

        final Intent intentToNotificate = new Intent(NotificationReceiver.ACTION_REFRESH_SCHEDULE_ALARM);
        pendingIntent = PendingIntent.getBroadcast(this, 0, intentToNotificate, 0);
    }

    @Override
    public void onStart(Intent intent, int startId) {
        try {

            long notificationInterval = 5002;

            alarmManagerPositioning.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime(), notificationInterval, pendingIntent);
        } catch (NumberFormatException e) {
            Toast.makeText(this, "error running services: " + e.getMessage(), Toast.LENGTH_SHORT).show();
        } catch (Exception e) {
            Toast.makeText(this, "error running services: " + e.getMessage(), Toast.LENGTH_SHORT).show();
        }
    }

    @Override
    public IBinder onBind(Intent arg0) {
        return null;
    }

    @Override
    public void onDestroy() {

        this.alarmManagerPositioning.cancel(pendingIntent);


    }
}

My question is how to call NotificationService in NotificationReceiver and change interval? Any help will be useful Thanks

  • 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-06-06T06:13:51+00:00Added an answer on June 6, 2026 at 6:13 am

    Start Service in your receiver using

    Intent in = new Intent(context,NotificationService.class);
    in.putExtra("interval",5001);
    context.startService(in);
    

    In your service code,

    long notificationInterval = intent.getLongExtra("interval", defaultValue)
    

    to get Data from your receiver, Please use onStartCommand(Intent intent, int flags, int startId), onStart has been deprecated.

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

Sidebar

Related Questions

Actually I have some MVC3 Applications and I want to call this applications from
I want to call my AuthenticationService from the code behind of my .net application.
I want to read a response from a non-wsdl web service call using JAXB.
I am new to titanium and and want to call a web service from
I have a web service with a import function i want to call from
Altova Mapforce create the console application now i want to call that console application
I Have an application in my account and I want to call a method
I have the following views in my application. Basically I want to call show_house()
I want to stop outgoing call and open the application. The app is able
I want to pause my android application when the phone receives an incoming call.

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.