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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:30:19+00:00 2026-05-25T21:30:19+00:00

Hi I have an Activity 1 which needs to send data to Appwidget (widget)

  • 0

Hi I have an Activity 1 which needs to send data to Appwidget (widget) which has a text view.

For sending data between activites i know that we can use intent.putExtra("mydata", dataString); and recive the same with String data = bundle.getString("mydata"); But in my case i need to send data (String) to app Widget.

When i use

Bundle dataFromPrevious = getIntent().getExtras();
String newString = dataFromPrevious.getString("mydata");

inside AppWidgetProvider it throws an error in getIntent saying getIntent is undefined for the type Class.

How can i get the string inside this AppWidget? Also this text will be updated from activity 1 with new string often so is using SharedPrefrences a good choice for this situation? Is there any other way?

UPDATE 1:

As mentioned by Joseph, i have added
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
in my manifest,

Now i have also created an OnRecieve Override in AppWidget

@Override
    public void onReceive(Context context, Intent intent) {

        Bundle getPrevData = intent.getExtras();
        String data = getPrevData.getString("mydata");
        newdata = data;
        super.onReceive(context, intent);
    }

In my On Update i have

views.setTextViewText(R.id.dataWidget,newdata);

Here the newdata is the public static String But it dose not display anything!!! when i setTextViewText to a textview in the widget. Am i missing something here? Please help…

UPDATE 2:

import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.RemoteViews;
import android.widget.Toast;

public class MainWidget extends AppWidgetProvider {

    private RemoteViews views;
    public static String newdata

    @Override
    public void onReceive(Context context, Intent intent) {

        Bundle getPrevData = intent.getExtras();
        String data = getPrevData.getString("mydata");
        newdata = data;

        super.onReceive(context, intent);
    }

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

        views = new RemoteViews(context.getPackageName(),R.layout.widget_layout);
        appWidgetManager.updateAppWidget(appWidgetIds, views);

        //views.setTextViewText(R.id.dataWidget,newdata);

        super.onUpdate(context, appWidgetManager, appWidgetIds);
    }


}

And this is my Another activityvthat sends data:

final String text = ((TextView)findViewById(R.id.textview)).getText().toString();
Intent intent = new Intent(FirstActivity.this, MainWidget.class);
                intent.putExtra("mydata", text);
  • 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-25T21:30:20+00:00Added an answer on May 25, 2026 at 9:30 pm

    You can update the data in widget without using Broadcast receiver.

    1. Save data in sharedPreference.

    2. Create the remote views using new data and use AppWidgetManager.updateWidget to update the widget.

    Here is the sample code.

    RemoteViews updateViews = buildUpdate(context); // Update the view using the new data.
    ComponentName thisWidget = new ComponentName(context, WidgetClassName.class);
    AppWidgetManager manager = AppWidgetManager.getInstance(context);
    manager.updateAppWidget(thisWidget, updateViews);
    

    This is what i did in my previous application.

    Saneesh CS

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

Sidebar

Related Questions

So I have an Activity (say TestActivity ) which needs to act as a
i have a service which fetches some data from network.i am sending data download
I have activity which needs to be active all the time. I have thread
I have an Activity, which needs its orientation to be locked with setRequestedOrientation(screenOrientation); But
I have an activity which shows some List entries. When I click on a
I have created an activity which sends a number of notifications to status bar.
I have a couple of tables which are used to log user activity for
Say if I have a locationManager(LM) object in activity A, which is my main
I have an activity that has a TabHost containing a set of TabSpecs each
I have an Android activity which in turn starts a thread. In the thread

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.