Pending intent not detecting onCreate

by jrgraf...@googlemail.com » Wed, 29 Apr 2009 08:19:21 GMT


Sponsored Links
 I have the following code in a static function in my application
widget:

                Intent defineIntent = new Intent(context,
ToggleIntentActivity.class);
                PendingIntent pendingIntent = PendingIntent
                                .getActivity(context, 0, defineIntent, 0);

                views.setOnClickPendingIntent(R.id.icon, pendingIntent);

                // Tell the widget manager
                appWidgetManager.updateAppWidget(appWidgetId, views);

custom activity's based on user clicks on your widgets. However even
though Logcat says Starting Activity: Intent {......} my activities on
create function never gets called!

Note my Activity is as follows:

public class ToggleIntentActivity extends Activity {
        @Override
        protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                Log.e(QuickerCutWidgetManager.TAG, "On create");
        }
}


Any ideas?
--~--~---------~--~----~------------~-------~--~----~



Pending intent not detecting onCreate

by jrgraf...@googlemail.com » Wed, 29 Apr 2009 08:52:16 GMT


 As a side note I also tried using LayoutInflator and attaching an
onClickListener to the imageview manually, but that failed to
recognise any events. Im guessing here that changes made via a
layoutinflator will not be picked up by remote views which later use
that layout?

On Apr 29, 1:19am, "jrgraf...@googlemail.com"


--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Pending intent not detecting onCreate

by Jeff Sharkey » Wed, 29 Apr 2009 11:41:27 GMT


 Hmm, not sure exactly why it isn't working.  Because you can't know
the state of the remote AppWidgetHostView holding your widget, you
should package up all operations each time you push an update.  You
said in logcat it looks like it's trying to start the activity, could
you paste the couple of lines surrounding that?

Also, if you don't have an <intent-filter> inside the Activity
definition in your manifest, you might need to add the
android:exported="true" flag.

j

On Tue, Apr 28, 2009 at 5:52 PM, jrgraf...@googlemail.com






-- 
Jeff Sharkey
jshar...@google.com

--~--~---------~--~----~------------~-------~--~----~



Pending intent not detecting onCreate

by jrgraf...@googlemail.com » Wed, 29 Apr 2009 18:40:36 GMT


 hanks for your reply Jeff,

Turns out what I really needed to do here was learn how Intent based
programming on Android works and how to actually implement it! What I
was missing here was actually declaring the activity in the Android
XML (I assumed that activities only had to be declared if they were
actually going to display something).

Still though I would be really nice if I could get direct access to
Button Widgets via LayerInflator so that I can directly manipulate the
background of the button, unfortunately the following seems to have no
effect:

LayoutInflater inflater = (LayoutInflater) context

.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.widget_layout, null);

Button button = (Button) view.findViewById(R.id.ToggleButton);
button.setBackgroundResource(R.drawable.airplaneoff);

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

Intent defineIntent = new Intent(context, ToggleActivity.class);
defineIntent.putExtra("toggle", toggle);
PendingIntent pendingIntent =
PendingIntent.getActivity(context, 0,
defineIntent, Intent.FLAG_ACTIVITY_NEW_TASK);

views.setOnClickPendingIntent(R.id.ToggleButton, pendingIntent);

// Tell the widget manager
appWidgetManager.updateAppWidget(appWidgetId, views);

No big deal tho since I can always use an ImageView and call
RemoteViews.setImageViewBitmap(id)

On Apr 29, 4:25am, Jeff Sharkey <jshar...@android.com> wrote:
--~--~---------~--~----~------------~-------~--~----~



Pending intent not detecting onCreate

by Jeff Sharkey » Thu, 30 Apr 2009 03:45:25 GMT


 ight, that wouldn't have an effect because your inflated layout is a
completely different copy from the one inflated by the home screen.

Also, I noticed that your using "putExtra" in your PendingIntents. Be
sure to use the FLAG_CANCEL_CURRENT flag when calling getActivity() to
make sure your extras are updated correctly. And be aware that you
can only have one set of extras for any given PendingIntent
action+data+category+component pair.

If you're trying to change the background of a button, you could use
this slightly-hacky approach: set the button background to a leveled
drawable, and then use setDrawableParameters() to change the level and
show the desired background.

You'd probably want to keep the number of layers to a minimum to keep it speedy.

j


On Wed, Apr 29, 2009 at 3:40 AM, jrgraf...@googlemail.com
<jrgraf...@googlemail.com> wrote:



--
Jeff Sharkey
jshar...@google.com

--~--~---------~--~----~------------~-------~--~----~



Pending intent not detecting onCreate

by jrgraf...@googlemail.com » Thu, 30 Apr 2009 05:31:13 GMT


 hanks for your help Jeff, its finally starting to make a lot more
sense now!

-James

On Apr 29, 6:43pm, Jeff Sharkey <jshar...@android.com> wrote:
--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. Fun & games with PopupWindow

Hi,
In my activity I'm experimenting to get an effect of a small button
floating over a list component in its bottom right corner. It seems
that there is no default view group component that would easily allow
for this. So I tried an approach of having a PopupWindow containing
the button rendered over the list. This is, roughly, the code I have
written:
private void initButton() {
        View buttonView =
getLayoutInflater().inflate(R.layout.keyboard_button, null);
        buttonPopup = new PopupWindow(buttonView);
buttonPopup.setWindowLayoutMode(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
        final View container = findViewById(android.R.id.tabhost); //
root view
        final View listContainer = findViewById(R.id.listContainer);
        container.post(new Runnable() { // showing in onCreate() or
onStart() impossible
            public void run() {
                buttonPopup.showAtLocation(container, Gravity.CENTER,
0, 0);
//                buttonPopup.update(listContainer, -1, -1);
//                buttonPopup.showAsDropdown(listContainer);
            }
        });
}

(where initButton is called in onStart()) Unfortunately, the
'showAtLocation' method does not work (the popup does not show in a
visible location). Surprisingly, when I uncomment the call to update
right after showAtLocation, or replace showAtLocation with the
commented out call to showAsDropdown, it works, i.e. displays the
button, but obviously not in the desired location (below the list
container, as opposed to within it, as the list container becomes the
anchor). I experimented with different values of Gravity (that's why
it's set to CENTER in the above code, originally it was RIGHT |
BOTTOM) and different values of x and y, but without success. I don't
know if it is relevant, but there is also a tab control involved in
this activity (the tabhost is the root view group). Any insights? Why
'showAtLocation' would not work? Perhaps there is a better way of
achieving what I want to achieve (i.e. without PopupWindow)?
Cheers,
Dariusz

-- 

2. NFC Intents: Reacting on specific NDEF types

Is it possible to restrict the type of tags an application is reacting
on?

The intent filter used e.g. by the Tags application on the Nexus-S is
defined as
   <intent-filter>
      <action android:name="android.nfc.action.TAG_DISCOVERED"/>
      <category android:name="android.intent.category.DEFAULT"/>
  </intent-filter>
When a tag is detected, the user has to choose the application which
should handle the intent.

I would like to react depending on the NDEF type of the record, e.g.
my application should be started if the NDEF record is of type
EXTERNAL and if the uri is "urn:nfc:ext:company.com:demo".

Is such an extension of the intent filter possile?
If not, is it planned?

Dominik

-- 

3. ListView in custom preference

4. How to draw button on canvas?

5. No <uses-feature name="vibration"/>; Do all android systems support vibration?

6. How can I android Market app for ginger bread

7. Isolated database tests