top ListActivity destroyed just after a Search has been initiated from it - was: Back key after Search doesn't return to list in 2.0 as it did in all earlier versions

by Jonas Petersson » Mon, 02 Nov 2009 06:20:33 GMT


Sponsored Links
 Hi again,

Hmm, it seems even more strange to me: the onDestroy() method of the top 
ListActivity is actually called very shortly after the search has 
triggered the onCreate()+onResume() methods that creates the second 
level ListActivity (note that this is the actual same class as the top 
one, just producing a different result due to the SEARCH action).
Call Sequence:

top onCreate()
top onResume()
-- I press search and enter some text.
top onPause()
2nd onCreate()
2nd onResume()
top onDestroy()
-- This is before the second ListActivity is even displayed

So obviously, by the time I press back in the 2nd ListActivity, there is 
no top ListActivity to show. So the problem is not the Back key, but 
that some unknown force has destroyed the top activity...

Note: the code is still compiled with android:minSdkVersion="2" and the 
very same package executes as expected on previous versions. So perhaps 
I've always done something incorrectly, but up until now the result was 
what I expected. In some special cases I do in fact explicitly call 
finish() to force this very effect, but that does not happen in this 
situation.

I didn't notice anything explicitly related to this in the release 
notes, but perhaps there is something between the lines that I have not 
yet realized.

                Advice appreciated / Jonas





--



top ListActivity destroyed just after a Search has been initiated from it - was: Back key after Search doesn't return to list in 2.0 as it did in all earlier versions

by Jonas Petersson » Tue, 03 Nov 2009 06:27:44 GMT


 ere we go again,

This time with full source: Just import into eclipse and build. Run with
any 1.6 or earlier device/emulator to get what I consider the expected
result. Run with any 2.0 emulator (or if you are lucky to have a device)
and you will see Toasts signalling that the primary display was
destroyed just when the secondary search screen has popped up.

If this is indeed how it is supposed to work in 2.0, what would be best
practice to make it work as it did in 1.6? (Preferably still built to
work on both pre-2.0 and 2.0+.)

Best / Jonas

Jonas Petersson wrote:

--


Sponsored Links


Other Threads

1. Need-help....Ganti touch screen htc eris

Guys....

Need help nih.....
HTC eris-ku touch screen-nya rusak nih.
Ada yg bs bantu ngga, utk daerah jogja dan sekitarnya.....
Tks

-- 
===============

2. Android Show Data from different SQLite Tables in ListActivity

Hey,

I got an ListActivity which gets its Data from a SQLite database. The
Database has 3 tables:

db.execSQL("CREATE TABLE " + TABLE_MAGAZINE + " (magazineId INTEGER
PRIMARY KEY, " +
                                                                                
                        "magazineName TEXT);");

            /** Tabelle "Edition" erstellen **/
            db.execSQL("CREATE TABLE " + TABLE_EDITION + " ( editionId
INTEGER PRIMARY KEY, " +
                                                                                
                        "editionName TEXT, " +
                                                                                
                        "editionContent TEXT, " +
                                                                                
                        "magazine_id INTEGER NOT NULL, " +
                                                                                
                        "FOREIGN KEY (magazine_id) REFERENCES " +
TABLE_MAGAZINE + "(magazineId));");

            /** Tabelle "Article" erstellen **/
            db.execSQL("CREATE TABLE " + TABLE_ARTICLE + " ( articleId
INTEGER PRIMARY KEY, " +
                                                                                
                        "articleName TEXT, " +
                                                                                
                        "articleContent TEXT, " +
                                                                                
                        "edition_id INTEGER NOT NULL, " +
                                                                                
                        "FOREIGN KEY (edition_id) REFERENCES " +
TABLE_EDITION + "(editionId));");




For the foreign Keys there are 2 Trigger:



 db.execSQL("CREATE TRIGGER fki_edition_magazine_id " +
                                " BEFORE INSERT ON "+ TABLE_EDITION +
                                " FOR EACH ROW BEGIN"+
                                " SELECT CASE WHEN ((SELECT magazineId FROM "+ 
TABLE_MAGAZINE +"
WHERE magazineId = new.magazine_id ) IS NULL)"+
                                " THEN RAISE (ABORT,'Foreign Key Violation') 
END;"+
                                "  END;");

            db.execSQL("CREATE TRIGGER fki_article_edition_id " +
                                " BEFORE INSERT "+
                                " ON "+ TABLE_ARTICLE +
                                " FOR EACH ROW BEGIN"+
                                " SELECT CASE WHEN ((SELECT editionId FROM "+ 
TABLE_EDITION +"
WHERE editionId = new.edition_id ) IS NULL)"+
                                " THEN RAISE (ABORT,'Foreign Key Violation') 
END;"+
                                "  END;");



Now I want to get the magazineName and the editionName and show them
in the ListView.

        Cursor getAllMagazines() {
                SQLiteDatabase db=this.getWritableDatabase();
                Cursor cur= db.rawQuery("SELECT * FROM edition, magazine WHERE
edition.magazine_id = magazine.magazineId", new String [] {});

                return cur;
        }


At the Moment I got 1 database-entry in every table in my DB. The
Cursor also got an Count by 1.
So i create a SimpleCursorAdapter to show the content in the ListView.

                        /** Adapter erstellen**/
                SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
                        android.R.layout.simple_list_item_2, c,
                        new String[] {"editionName", "magazineName"},
                        new int[] {android.R.id.text1, android.R.id.text2});

                        /** Adapter setzen**/
                    this.setListAdapter(adapter);

        this.setListAdapter(adapter);


The count of the cursor is 1, and the column names are editionName and
magazineName (LogCat). But it wont show any data.

If i use an extra attribute id INTEGER PRIMARY KEY AUTO_INCREMENT and
i only want Data from 1 Tabel, everything works fine.

Any ideas?

-- 

3. Android Eclipse plugin: setting background in wysiwyg didn't set background

4. Android Mp3 Intent: Shazam does it, how do we?

5. Memory management - is usage of direct arguments bad?

6. Android Mp3 Intent: Shazam does it, how do we?

7. WebView Animation Problem