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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:29:45+00:00 2026-06-03T20:29:45+00:00

I am trying to create an application with a widget. When the user places

  • 0

I am trying to create an application with a widget. When the user places the widget on the desktop a listview should come up with a list of items. The user selects an item then the widget is created with the respective text related to that item. For simplicity I am using now an alertdialog. The input text should appear only in the widget I create. It should not appear in the other widgets. How am I supposed to do that? I have not found anyhing about this.

The AppWidgetProvider:

public class MyWidgetProvider extends AppWidgetProvider {

    private static final String ACTION_CLICK = "ACTION_CLICK";

    @Override
    public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {

        Log.i("INFO", "AppWidgetProvider"); 

        ComponentName thisWidget = new ComponentName(context, MyWidgetProvider.class);
        int[] allWidgetIds = appWidgetManager.getAppWidgetIds(thisWidget);
        //Intent intent = new Intent(context.getApplicationContext(),   UpdateWidgetService.class);
        //intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, allWidgetIds);
        //context.startService(intent);
            Intent intentA = new Intent(context.getApplicationContext(), NoteListToWidget.class);
    intentA.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intentA);

        }

}

The service:

public class UpdateWidgetService extends Service {
    public static String ACTION_WIDGET_CONFIGURE = "ConfigureWidget";
    public static String ACTION_WIDGET_RECEIVER = "ActionReceiverWidget";
    String value;
    Dialog dialog_newitem;


    @Override
    public void onStart(Intent intent, int startId) {
        Log.i("INFO", "UpdateWidgetService");

        AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this.getApplicationContext());

        int[] allWidgetIds = intent.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS);

        ComponentName thisWidget = new ComponentName(getApplicationContext(), MyWidgetProvider.class);
        int[] allWidgetIds2 = appWidgetManager.getAppWidgetIds(thisWidget);

        for (int widgetId : allWidgetIds) {
            int number = (new Random().nextInt(100));
            String v = GlobalVars.getValue();
            RemoteViews remoteViews = new RemoteViews(this.getApplicationContext().getPackageName(), R.layout.widget_layout);
            //remoteViews.setTextViewText(R.id.update, "Random: " + String.valueOf(number));
            remoteViews.setTextViewText(R.id.update, v);

            Intent configIntent = new Intent(this, Notepad.class);
            configIntent.setAction(ACTION_WIDGET_CONFIGURE);
            PendingIntent configPendingIntent = PendingIntent.getActivity(this, REQUEST_CODE_ONE, configIntent, PendingIntent.FLAG_UPDATE_CURRENT);
            remoteViews.setOnClickPendingIntent(R.id.widgetlayout, configPendingIntent);

            appWidgetManager.updateAppWidget(widgetId, remoteViews);
        }
        stopSelf();

        super.onStart(intent, startId);


    }

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

This is the Activity with the AlertDialog (the latter listview):

public class NoteListToWidget extends Activity {

    Dialog dialog_newitem;
    EditText et_newitem;
    String value;

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


        dialog_newitem = new Dialog(NoteListToWidget.this);
        dialog_newitem.setContentView(R.layout.dialog_productlists_grp_capitalized);
        dialog_newitem.setTitle("Select");
        dialog_newitem.setCancelable(true);

        et_newitem = (EditText) dialog_newitem.findViewById(R.id.et_item_name);

        Button btn_Save = (Button) dialog_newitem.findViewById(R.id.btn_save_pr);
        btn_Save.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                value = et_newitem.getText().toString();
                 GlobalVars.setValue(value);
                dialog_newitem.dismiss();
                /*
                Intent serviceIntent = new Intent();
                serviceIntent.setAction("com.myapp.app.UpdateWidgetService");
                startService(serviceIntent);
                */
                Intent intent = new Intent(NoteListToWidget.this, com.myapp.app.UpdateWidgetService.class);
                startService(intent);

            }
            });


        Button btn_Cancel = (Button) dialog_newitem.findViewById(R.id.btn_cancel_pr);
        btn_Cancel.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                dialog_newitem.dismiss();
            }

        });
        dialog_newitem.show();



    }

}

I don’t how and from where should I call the NoteListToWidget activity and how to make this whole thing work.

  • 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-03T20:29:47+00:00Added an answer on June 3, 2026 at 8:29 pm

    First of all it is impossible to answer your question in full. This is because it seems you are missing a lot of things about how app-widgets are working, so you must read more about them. However I will give you a place to start.

    The onUpdate method of the AppWidgetProvider is called each time an app-widget that it is already placed on the desktop needs an update. That is, even if you manage to display your list from there and the user cancels the operation there is NO way to remove your app-widget from the onUpdate method.
    Furthermore when the onUpdate method finishes the AppWidgetProvider is destroyed, so even if you manage to display your list from there there is NO way to get the items that user selected. Long story short, you canNOT do it from onUpdate method and you canNOT do it by this approach.

    However, you CAN do it by using a configuration activity in a specified point of the app-widget’s creation process but this cannot be answered in the context of your question because you must first understand how the app-widget system works in Android. The best place to start is this link. I had the same problems with my first app-widget application (and almost the same concerns with you) but then I started to read and read, finally after 1.5 months I ‘ve managed to make something like the thing you want to do. So don’t say

    How am I supposed to do that? I have not found anyhing about this

    and start reading, this is the life with Android. It’s all in the above link, there are also very good open-source projects in google code like this weather widget which allows the user to configure it BEFORE it is placed on the desktop.

    Hope this helps…

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

Sidebar

Related Questions

I am trying to create an application with a widget. When the user places
I'm trying to create a custom Dojo widget for my application. <!-- Dojo widget
I am trying to create an application that has a background image with widget
Im trying to create application from scratch. In new maven project i add a
I am trying to create an application that makes a window (external to the
I'm trying to create an application where there is a JSplitPane which contains the
I'm trying to create an application that uses the iPhone MapView (under Google Code).
I'm trying to create an application in interface builder, and I'm having a problem.
I am trying to create an application can modify properties in IL to create
I am trying to create an application to take advantage of OpenSSH to create

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.