2

I have a problem with widgets and actions

In configurator class, i set up for the whole widget and for button the listeners:

 //the first one when we click on the button
 Intent firstIntent = new Intent(c.getApplicationContext(), ShowDetailedCityWeather.class);
 // Intent firstIntent = new Intent(WeatherWidget.ACTION_WIDGET_RECEIVER);
 PendingIntent myPI = PendingIntent.getActivity(c, 0, firstIntent, 0);
 firstIntent.setAction("Привет мир");
 remoteViews.setOnClickPendingIntent(R.id.imageButton1, myPI);
 firstIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, awID);

 //the second one when we click on widget
 Intent secondIntent = new Intent(ChoiseCityList.this, MainTelephoneActivity.class);
 PendingIntent myPI2 = PendingIntent.getActivity(c, 0, secondIntent, 0);
 remoteViews.setOnClickPendingIntent(R.id.newLinearLayout, myPI2);


 manager.updateAppWidget(awID, remoteViews);

When I click on the button, the new Activity ShowDetailedCityWeather starts runnig. How can I detect the ID of widget in this activity, when I have many widgets? And also I want to get data from widget. I try:

Intent prevIntent = getIntent();
if(prevIntent != null)
 Toast.makeText(this, "Hello:" + prevIntent.getAction(), Toast.LENGTH_SHORT).show();
else
 Toast.makeText(this, "Help!", Toast.LENGTH_SHORT).show();

In Toast I have: Hello: null

Then I have tryed:

int awID = -90;
        Context c = ShowDetailedCityWeather.this;
        Intent intentWidget = getIntent();
        Toast.makeText(c, "Action : " + intentWidget.getAction(), Toast.LENGTH_SHORT).show();

        Bundle extras = intentWidget.getExtras();
        if(extras!=null)
           awID = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
        Toast.makeText(c, "ID : " + awID, Toast.LENGTH_SHORT).show();

And I always have -90. Can you please help me...

enter code here
4

0 回答 0