Gracefully destroying Dialog box

by Neilz » Fri, 23 Oct 2009 20:11:55 GMT


Sponsored Links
 Hi. I have an activity which pops up a Dialog box, to get some text
input from the user. The problem arises when you switch orientation.
The Dialog disappears, so I have added code to set and check flags in
the savedInstanceState, meaning that the Dialog is displayed again in
these circumstances.

However, the dialog isn't being closed gracefully when the orientation
is switched. I get the following error:


10-23 12:53:54.385: ERROR/WindowManager(2852): Activity
com.bla.bla.Bla has leaked window
com.android.internal.policy.impl.phonewindow$decorv...@435ceda0 that
was originally added here
10-23 12:53:54.385: ERROR/WindowManager(2852):
android.view.WindowLeaked: Activity com.bla.bla.Bla has leaked window
com.android.internal.policy.impl.phonewindow$decorv...@435ceda0 that
was originally added here


I know when the window is going to be closed, but can't find a way of
closing it manually. I open it with alert.show();  ...but there
doesn't seem to be any corresponding alert.destroy() method or
similar.

Any ideas how I can manually close the dialog box without user input?
--~--~---------~--~----~------------~-------~--~----~



Gracefully destroying Dialog box

by Neilz » Sat, 24 Oct 2009 16:46:35 GMT


 Oh well. Maybe I should raise it as a bug, as this is a problem to me,
and it seems there should be a standard method to the effect of
alert.close();



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


Sponsored Links


Gracefully destroying Dialog box

by Lance Nanek » Sat, 24 Oct 2009 17:13:00 GMT


 You can close a dialog using its dismiss() method :
 http://developer.android.com/intl/fr/reference/android/app/Dialog.html #dismiss%28%29

You might want to consider having the activity manage restoring your
dialog for you as well:
 http://developer.android.com/intl/fr/reference/android/app/Activity.html #onCreateDialog%28int%29




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



Other Threads

1. A lot of graphics in drawable-folder

Hi, I have plenty of image files in my drawable folder because my
application has different skins. This makes it very unmanageable. But
is there a better to organize the graphics, like folders, groups or
such things? Or is it a good idea to not use the drawable resource,
but instead create a xml file in the application directory for each
skin with the image-links?
--~--~---------~--~----~------------~-------~--~----~

2. SimpleCursorAdapter and blobs

hi,
the favicon field returned by the browser bookmark provider is a
sqlite blob.
I want to display the bookmarks in a listview with the favicon but
couldn't find a way to do it.
I tried using a SimpleCursorAdapter.ViewBinder but I get an exception.

this is what my code looks like :


                Cursor bookmarks;
                String[] proj = new String[] {
                        android.provider.Browser.BookmarkColumns.URL,
                        android.provider.Browser.BookmarkColumns.TITLE,
                        android.provider.Browser.BookmarkColumns.FAVICON
                };
                bookmarks = managedQuery(android.provider.Browser.BOOKMARKS_URI,
proj, null, null, android.provider.Browser.BookmarkColumns.URL  + "
ASC");

                SimpleCursorAdapter adapter = new SimpleCursorAdapter(
                                this,
                                R.layout.bookmark_element,
                                bookmarks,
                                new String[] 
{android.provider.Browser.BookmarkColumns.URL,
android.provider.Browser.BookmarkColumns.TITLE,
android.provider.Browser.BookmarkColumns.FAVICON},
                                new int[] { R.id.url,R.id.titre, R.id.icon});
                adapter.setViewBinder(new BookmarkDataViewBinder());
                setListAdapter(adapter);


and this is my viewbinder class :

class BookmarkDataViewBinder implements SimpleCursorAdapter.ViewBinder
{
        @Override
        public boolean setViewValue(View view, Cursor cursor, int
columnIndex) {
                
if(view.getClass().getName().equals("android.widget.ImageView")) {
                        byte[] b = cursor.getBlob(columnIndex);
                        if(b != null) {
                                Bitmap bitmap = 
BitmapFactory.decodeByteArray(b, 0, b.length);
                                ((ImageView)view).setImageBitmap(bitmap);
                        }
                        else {
                                
((ImageView)view).setImageResource(R.drawable.icon);
                        }
                        return true;
                }
                return false;
        }
}


if the favicon blob field is null, the viewbinder does its job and it
displays the default icon. but if it is not null, this is the
exception I get :

E/AndroidRuntime( 1365): Uncaught handler: thread main exiting due to
uncaught exception
E/AndroidRuntime( 1365): android.database.sqlite.SQLiteException:
unknown error: Unable to convert BLOB to string
E/AndroidRuntime( 1365):        at
android.database.CursorWindow.getString_native(Native Method)
E/AndroidRuntime( 1365):        at
android.database.CursorWindow.getString(CursorWindow.java:278)
E/AndroidRuntime( 1365):        at
android.database.AbstractWindowedCursor.getString
(AbstractWindowedCursor.java:49)
E/AndroidRuntime( 1365):        at
android.database.CursorWrapper.getString(CursorWrapper.java:135)
E/AndroidRuntime( 1365):        at
android.widget.SimpleCursorAdapter.bindView(SimpleCursorAdapter.java:
119)
E/AndroidRuntime( 1365):        at android.widget.CursorAdapter.getView
(CursorAdapter.java:186)
E/AndroidRuntime( 1365):        at
android.widget.AbsListView.obtainView(AbsListView.java:1057)
E/AndroidRuntime( 1365):        at
android.widget.ListView.makeAndAddView(ListView.java:1622)
E/AndroidRuntime( 1365):        at android.widget.ListView.fillDown
(ListView.java:607)
E/AndroidRuntime( 1365):        at android.widget.ListView.fillGap
(ListView.java:578)
E/AndroidRuntime( 1365):        at
android.widget.AbsListView.trackMotionScroll(AbsListView.java:2232)
E/AndroidRuntime( 1365):        at android.widget.AbsListView
$FlingRunnable.run(AbsListView.java:2064)
E/AndroidRuntime( 1365):        at android.os.Handler.handleCallback
(Handler.java:542)
E/AndroidRuntime( 1365):        at android.os.Handler.dispatchMessage
(Handler.java:86)
E/AndroidRuntime( 1365):        at android.os.Looper.loop(Looper.java:
123)
E/AndroidRuntime( 1365):        at android.app.ActivityThread.main
(ActivityThread.java:3739)
E/AndroidRuntime( 1365):        at
java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 1365):        at java.lang.reflect.Method.invoke
(Method.java:515)
E/AndroidRuntime( 1365):        at com.android.internal.os.ZygoteInit
$MethodAndArgsCaller.run(ZygoteInit.java:739)
E/AndroidRuntime( 1365):        at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:497)
E/AndroidRuntime( 1365):        at dalvik.system.NativeStart.main
(Native Method)


according to my logs, the exception occurs before my viewbinder is
called.

can somebody help?
thanks

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

3. Terminal and su error

4. why my setting dns can't work

5. NotePad tutorial, trouble removing notes

6. how to use HTTP Session with StreamingMediaPlayer

7. ADT Plugin