简体   繁体   中英

Android application exits without any exception

I'm building an application that shows in a WebView some remote data that is cached in SQLite db. The data is being requested by JavaScript function from WebView via JavaScript interface.

When user types into an input element on the page, JavaScript function requests search result by calling Java function, which in turn fires a sql query. Results are then packaged in suitable JSON format and returned.

Fetching data works OK unless you type very quickly. If you type quick enough after few key presses the app quits WITHOUT any exceptions being thrown, it just goes back to home screen.

I have managed to narrow down the cause - commenting out the call to .query method prevents crashing, but renders app useless.

Is there a way to check what caused application to quit, another log or tool that could help?

Java function code:

    public Lot[] getLotList(String query, int limitCount) {
    ...
    ...
    String[] resultColumns = new String[] { LotsSearch._ID };
    String queryWhere = LotsSearch.TABLE_NAME + " MATCH ?";
    String[] queryArgs = new String[] { query + "*" };
    String sortOrder = LotsSearch.COLUMN_NAME_NUMBER + " ASC, " + LotsSearch.COLUMN_NAME_TITLE + " ASC";
    String limit = null;
    Cursor cursor = null;
    if (limitCount != -1)
        limit = "0," + limitCount;
    try {
        cursor = mDb.query(LotsSearch.TABLE_NAME, resultColumns, queryWhere, queryArgs, null, null, sortOrder, limit);
        if (cursor != null && cursor.moveToFirst()) {
            result = new Lot[cursor.getCount()];
            try {
                int idColumnIndex = cursor.getColumnIndexOrThrow(LotsSearch._ID);
                int lotId;
                Lot lot;
                do {
                    lotId = cursor.getInt(idColumnIndex);
                    lot = mLots.get(lotId);
                    if (lot != null)
                        result[index++] = lot;
                } while (cursor.moveToNext());
            } catch (IllegalArgumentException e) {
                e.printStackTrace();
            }
        }
    } catch (SQLiteException e) {
        e.printStackTrace();
    } finally {
        if (cursor != null)
            cursor.close();
    }
    ...
    ...
    return result;
}

UPDATE:

I have discovered that there is another log that could be accessed by issuing

logcat -b events

when the app crashes there is just one entry

I/am_proc_died(   59): [11473,com.example.app] 

and when the app exits gracefuly this log shows set of entries:

I/am_finish_activity(   59): [1157978656,22,com.example.app/.MainActivity,app-request]
I/am_pause_activity(   59): [1157978656,com.example.app/.MainActivity]
I/am_on_paused_called(11473): com.example.app.MainActivity
I/am_destroy_activity(   59): [1157978656,22,com.example.app/.MainActivity] 

I'd make a change to my auto search function. Namely, only perform the search if the user hasn't pressed a key for about 1/2 a second.

If you are typing fast, then this function is being executed several times right on top of itself, before the results are even able to come back. Meanwhile you are probably have too many cursor resources going at once causing the app to just completely fail.


update . If you consider it, typing 10 keys fairly quickly in a row could potentially mean that you have 10 different queries executing and parsing results... There could certainly be some deadlocking issues with the code that actually calls the getLotList method if it's spun multiple threads to try and update the UI. This can lead to some programs simply giving up the ghost not knowing what to do or even what thread to report the issue on.

Of course, all of that's hard to tell from the small snippet we have.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM