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

  • Home
  • SEARCH
  • 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 8447949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:18:02+00:00 2026-06-10T10:18:02+00:00

I will make it simple. I have my widget code. My widget layout contains

  • 0

I will make it simple. I have my widget code. My widget layout contains a linear layout with one button in it. In my widget code, I initialize a String List with some values in it.
When I click the button in my widget, I have to update my List with some more values.

So, this is my code,

List<String> myList = null;
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
        int[] appWidgetIds) {
myList = new List<String>();
myList.add("1");
myList.add("2");
...
Intent intent = new Intent(context, getClass());
intent.setAction("CALL_UPDATE");
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, 0);
views.setOnClickPendingIntent(R.id.button, pendingIntent);
....
}

@Override
public void onReceive(Context context, Intent intent) {
    if (intent.getAction().equals("CALL_UPDATE")) {
        Toast.makeText(context, "Intent received"+myList , 2000).show();
    }
}

When the button is clicked, the broadcast is properly received by onReceive(). The problem is, on onReceive(), I see my list as null instead of some values in it as some string objects were added earlier.

Can anyone help?

Thx!
Rahul.

  • 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-10T10:18:03+00:00Added an answer on June 10, 2026 at 10:18 am

    Documentation says:

    This has important repercussions to what you can do in an
    onReceive(Context, Intent) implementation: anything that requires
    asynchronous operation is not available
    , because you will need to
    return from the function to handle the asynchronous operation, but at
    that point the BroadcastReceiver is no longer active and thus the
    system is free to kill its process before the asynchronous operation
    completes.

    In particular, you may not show a dialog or bind to a service from
    within a BroadcastReceiver. For the former, you should instead use the
    NotificationManager API. For the latter, you can use
    Context.startService() to send a command to the service.

    And:

    onReceive() is normally called within the main thread of its process,
    so you should never perform long-running operations in it (there is a
    timeout of 10 seconds that the system allows before considering the
    receiver to be blocked and a candidate to be killed). You cannot
    launch a popup dialog in your implementation of onReceive().

    Edit:
    AppWidgetProvider is a BroadcastReceiver and it’s instance (and so it’s fields) will be deleted after it’s lifcycle.When you create a new instance of widget in HomeScreen,onUpdate and onReceive of AppWidgetProvider invoke and list of this instance of AppWidgetProvider is not null.But after invoking onReceive (for example 10 seconds)this instance will delete.When you click on button ,second instance of AppWidgetProvider will be create and it’s list is null.
    You can save your list public static field of a class and retrieve it when you need.

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

Sidebar

Related Questions

I will make this quick and simple I have a query and I want
Basically I want to make simple toggle program (that will be mapped to some
I'm attempting to make a simple linear text game that will display inside a
Ho to make this simple xml with php using DOM? Full code will be
I will try to make this simple and quick.. I have never attempted this
I am trying to make a simple application which will send the user to
I want to make a simple app, where a UIWebView with custom content will
Simple question, I make an application for my phone (android froyo). Is it will
I'm trying to make an online MMO in Java. It will be a simple
I will make upload my application today to my homepage and wanna to have

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.