Only use the application context if you need something that persists for the lifetime of your process, and don't need to use it to do any UI (because it is not associated with an activity UI session).
Generally if in doubt, pretend like it doesn't exist and don't use it. On Fri, Aug 28, 2009 at 3:46 PM, eags <eagsala...@gmail.com> wrote: > > Ok, so the code below started working as soon as I switched from > getApplicationContext (which I thought was safe here) to > SmsDecorator.this. > > I've been a little confused about which to use where for a while. Can > anyone please clarify the differences and where it it best to use one > over the other?? > > Thanks. > > > On Aug 28, 3:24 pm, eags <eagsala...@gmail.com> wrote: > > I'm trying to pop up an AlertDialog when someone long presses a list > > item. What I end up with is nested callback objects. I'm not sure if > > that is the problem but simple Alert dialog examples are not working > > for me. Here is what I want and is crashing: > > > > smsContactsListView.setOnItemLongClickListener(new > > OnItemLongClickListener() { > > @Override > > public boolean onItemLongClick(AdapterView<?> > parent, View view, > > int position, final long id) { > > > > new AlertDialog.Builder(getApplicationContext()) > > .setTitle("Alert") > > .setMessage("Really Delete SMS Contact?") > > .setPositiveButton("Ok", new > DialogInterface.OnClickListener > > () { > > @Override > > public void > onClick(DialogInterface dialog, int which) { > > > dbAdapter.removeSmsContact(id); > > smsContactsCursor.requery(); > > } > > }) > > .setPositiveButton("Cancel", new > > DialogInterface.OnClickListener() { > > @Override > > public void > onClick(DialogInterface dialog, int which) { > > } > > }) > > .show(); > > > > // return true to indicate we consumed the > callback > > return true; > > } > > }); > > > > Here is what works (no dialog at all): > > > > smsContactsListView.setOnItemLongClickListener(new > > OnItemLongClickListener() { > > @Override > > public boolean onItemLongClick(AdapterView<?> > parent, View view, > > int position, final long id) { > > > > // This works for now > > dbAdapter.removeSmsContact(id); > > smsContactsCursor.requery(); > > > > // return true to indicate we consumed the > callback > > return true; > > } > > }); > > > -- Dianne Hackborn Android framework engineer hack...@android.com Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails. All such questions should be posted on public forums, where I and others can see and answer them. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---