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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:07:17+00:00 2026-06-14T18:07:17+00:00

I have an app widget with a configuration activity. When I click done in

  • 0

I have an app widget with a configuration activity. When I click “done” in the config activity the widget come out. If that’s the first time I use the widget, it will be blank, in that’s not the first time, it update with the data from my previous use of the configuration activity. The widget gets its data from SharedPrefences. Previous instance of the widget won’t get updated with the new data.
No error on LogCat. Here is some code:
AppWidgetProvider

public class DogTagWidgetProvider extends AppWidgetProvider {

public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    for (int widgetId : appWidgetIds)
    {
        updateWidget(context, appWidgetManager, widgetId);
    }
}



public  void updateWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId){
    //Get RemoteViews and SharedPreferences
    RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.dogtag_widget);
    SharedPreferences settings = context.getSharedPreferences(DogTagConfigure.PREFS_NAME, Context.MODE_MULTI_PROCESS);



    //Check Name
    String name = settings.getString("name", null);
    boolean nameB = settings.getBoolean("nameB", false);
    if(!nameB){
        views.setViewVisibility(R.id.llName, View.GONE);
    }else {
        views.setTextViewText(R.id.tvName, name);
    }
    //Check Address
    String address = settings.getString("address", null);
    boolean addressB = settings.getBoolean("addressB", false);
    if(!addressB){
        views.setViewVisibility(R.id.llAddress, View.GONE);
    }else {
        views.setTextViewText(R.id.tvAddress, address);
    }
    //Check Phone Number
    String phoneNumber = settings.getString("phoneNumber", null);
    Boolean phoneNumberB = settings.getBoolean("phoneNumberB", false);
    if(!phoneNumberB){
        views.setViewVisibility(R.id.llNumber, View.GONE);
    }else {
        views.setTextViewText(R.id.tvNumber, phoneNumber);
    }

    //TODO Show Owner Photo
    String photoUri = settings.getString("photoUri", null);
    if(!(photoUri==null)){
        Uri photoURI = Uri.parse(photoUri);
        views.setImageViewUri(R.id.ivPhoto, photoURI);
    }else{
        views.setViewVisibility(R.id.ivPhoto, View.GONE);
    }

    //TODO Cancel the remove and write code for this action
    views.setViewVisibility(R.id.llSend, View.GONE);
    /*
    Intent labelIntent = get_ACTION_APPWIDGET_UPDATE_Intent(context);
    PendingIntent labelPendingIntent = PendingIntent.getBroadcast(context,
            appWidgetId,
            labelIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
     */
    Log.d("updateAppWidget", "Updated ID: " + appWidgetId);

    //Update Widget
    appWidgetManager.updateAppWidget(appWidgetId, views);
}

Configure Activity (some part):

   //DONE pressed
public void done(){
    savePref();

    Intent firstUpdate = new Intent(context, DogTagWidgetProvider.class);
    firstUpdate.setAction("android.appwidget.action.APPWIDGET_UPDATE");
    firstUpdate.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);
    context.sendBroadcast(firstUpdate);
    Log.d("Ok Button", "First onUpdate broadcast sent");

    Intent resultValue = new Intent();
    resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetID);
    setResult(RESULT_OK, resultValue);
    finish();
}

//DISCARD pressed
public void discard(){
    Intent resultValue = new Intent();
    resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetID);
    setResult(RESULT_CANCELED, resultValue);
    finish();


}


//Save new preferences
private void savePref() {
    name = etName.getText().toString();
    address = etAddress.getText().toString();
    phoneNumber = etNumber.getText().toString();


    SharedPreferences.Editor editor = settings.edit();
    editor.putString("name", name);
    editor.putBoolean("nameB", nameB);
    editor.putString("address", address);
    editor.putBoolean("addressB", addressB);
    editor.putString("phoneNumber", phoneNumber);
    editor.putBoolean("phoneNumberB", phoneNumberB);
    editor.putString("photoUri", photoUri);
    editor.putBoolean("ownerFound", ownerFound);
    editor.commit();
}
  • 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-14T18:07:18+00:00Added an answer on June 14, 2026 at 6:07 pm

    SharedPreferences are laggy. You could take that code in onUpdate of your AppWidgetProvider and call it in your ConfigurationActivity (which’ll ensure the value is immediately displayed after the first deployment at least).

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

Sidebar

Related Questions

I have a widget that supposed to call an Activity of the main app
Say that there is an App Widget that shows a configuration Activity when placed.
I have a widget that is a part of my main app. Usually when
i want to create a widget app that when added will start ConfigurationActivity which
I have an express app that I want to use the connect-form module on
I have an app with a main activity and an app widget. The app
I have an app widget project, which relies that a corresponding app is installed.
We have a web app (let's call it widget app) that contains data I
Say my app has a widget and I use a configuration screen to do
I have one configuration activity and multiple app widgets for the same app. When

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.