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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:07:31+00:00 2026-05-26T14:07:31+00:00

Good day, I have an activity which i navigate to from an icon on

  • 0

Good day, I have an activity which i navigate to from an icon on an appwidget using pending Intents. Everything is being done in a service class. Now, the activity has a refresh button which when pressed, it sends an intent that calls the onStart() method on the service to update itself and perform some web operations. How do i go about reflecting the changes that could have occurred from the service in the activity without temporarily existing the activity.

Service to Activity:

if(intent.getExtras()!= null){
      appWidgetId = intent.getExtras().getInt(AppWidgetManager.EXTRA_APPWIDGET_ID);

      //if i get this action from my detailedinfo class add a boolean to it

      if(intent.getAction() == refresh_action){

     // boolean variable to hold condition
          my_action = true;
      }



Intent forecast = new Intent(this,detailedInfo.class );
    forecast.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
        forecast.putExtra("cityname", city);

 PendingIntent forecastIntent = PendingIntent.getActivity(this, 0, forecast, 0);

        /*onclick to go to detailedInfo class*/
        remoteView.setOnClickPendingIntent(R.id.city_image_id, forecastIntent);


        if(my_action == true){          
            //Log.d(TAG, "my_action is true, performing pending intent");

            try {
                forecastIntent.send(this, 0, forecast);
            } catch (CanceledException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

And in the Activity class:

Intent service = new Intent(this, cityService.class);
        service.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
        service.setAction(refresh_action);
        Uri data = Uri.withAppendedPath(Uri.parse(CityWidgetProvider.URI_SCHEME + "://widget/id/"), String.valueOf(appWidgetId));
        service.setData(data);
               startService(service);

I tried adding a setAction() method to the intent that calls the service and then use the same pendingIntent(even though i think is a long shot) but they seems to be ignored. Please how do i go about this and what could i have been doing wrong.? As usual any help is highly appreciated. Thank you.

  • 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-26T14:07:32+00:00Added an answer on May 26, 2026 at 2:07 pm

    I’m not 100% clear on what you’re trying to do, but the easiest thing to do would be to register a BroadcastReceiver in your Activity onResume (remove it in onPause). When the service is done with whatever it needs to do, broadcast that info.

    In the Activity

    public static final String ACTION_STRING = "THE_BIG_ACTION";
    private BroadcastReceiver receiver = new BroadcastReceiver() {
    
            @Override
            public void onReceive(Context context, Intent intent) {
                // Do whatever you want here
                Toast.makeText(getApplicationContext(), "received", Toast.LENGTH_SHORT);
    
            }
        };
    
        @Override
        protected void onResume() {
            super.onResume();
            registerReceiver(receiver, new IntentFilter(ACTION_STRING));
        }
    
        @Override
        protected void onPause() {
            super.onPause();
            unregisterReceiver(receiver);
        }
    

    In the service, when you’re done, just call…

    sendBroadcast(new Intent(YourActivityClass.ACTION_STRING));
    

    If you want to include some data, just put it in the intent like you would when starting an Activity.

    If your Activity is off screen when the service completes, and the user goes back to it, you’ll have missed the notification. That’s a different issue to resolve.

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

Sidebar

Related Questions

Good day. I have an app that has one main activity which holds 3
Good day, If I have for example the documents which have the following fields
Good day I have a basic toolbar to which I added ImageIcon buttons. The
Good day, I have a gen_server process which does some long-running state-updating tasks periodically
Good day everyone. I have a question about making and using derived classes of
Good day, I have an application written using the Symfony framework. The application works
Good day, I have a hibernate mapping which goes something like this <class name=Person>
Good day! I have met problem with synchronizing threads. I am writing program which
Good Day, We have migrated our web application to ASP.NET 2.0 from ASP.NET 1.1.
Good day, I have a problem in a .NET page where I am using

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.