• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

Android search and suggestion provider affect parent activity lifecycle under certain conditions

Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Came across a weird 'feature' that is causing me some grief. We've implemented a search suggestion provider and search activity (android.app.default_searchable) in our application. The issue is that if the android quick search box fires an intent to our defined search
activity AND that activity does not result in a new activity becoming visible, then the activity that was active when the search key was pressed
will NOT fire onDestroy() until a visible activity is launched from it first.

As long as we fire off a VISIBLE activity from our defined search activity, it works fine, the parent life cycle works normally and when we back out of it onDestroy() fires. If our search activity fires off an activity that does not become visible, UNTIL we do something in the parent activity to cause it to create
a visible activity, onDestroy() will not fire when I back out of the parent activity.

In the onCreate of our search activity, we evaluate a few things, primarily, did the user select one of our suggestions in the quick search box or did they search on key word. If they search on key word our search activity is also a list activity so it shows a list of results that they can select. Because we are 'showing' something searching on keywords does not affect the parent lifecycle.

If however the user selected one of our suggestions, our search activity never becomes visible, it retrieves the selected item from the intent that the quick search box sends, and puts focus on that item in the parent activity. At this point, UNTIL some activity besides the parent activity becomes visible, the parents onDestroy will not fire when backed out of.

It seems like something is 'stuck' somewhere in the stack, as if the parent has some pending....something...that prevents onDestroy from firing.

This behavior seems to be consistent in v2.0 and v2.1.

Our searchable.xml looks like this:

<searchable xmlns:android="http://schemas.android.com/apk/res/android"

Our search activity is defined in our manifest like so: Note that I added launchMode and noHistory in an attempt
to correct this issue.
<activity android:name="OurSearchActivity"
<action android:name="android.intent.action.SEARCH" />
<category android:name="android.intent.category.DEFAULT" />

Our parent activity has the following meta-data assigned in the manifest:
android:value="OurSearchActivity" />

Our application search suggestion provider is defined in the manifest:
android:syncable="false" />

onCreate of our application defined search activity is where the issue starts to come into play based on my debugging.
Following the code is a description of the various parts of the code.

In the first part of the if statement, if the queryAction is an ACTION_SEARCH it means the user did not select a
suggestion, and instead searched on keywords. At this point because our search activity is also a list activity
we populate a visible list of results based on those keywords. When this happen our parent life cycle works
correctly, apparently because a 'visible' activity resulted after the search.

If the else part of the if statement, when queryAction is an ACTION_VIEW it means that the user picked one of
our suggestions. Inside of that the code in fires off an Intent that
results in a visible activity that is not the parent of the search. Again, because of this the parent activity
life cycle works fine.

It is the next two else statements that cause the problem

Originally looked just like
in that it directly accessed the parent activity and the search activity finished. As a test I tried to fire off an Intent
to the parent activity instead of directly accessing it (and processing the request in the Parent activities newIntent() method).

In either case, because neither


fires off a visible Activity that is not the parent Activity, the parent Activities life cycle ceases to work normally. At this point until
a visible activity is fired off by the user (or by me), the parent activity will not fire onDestroy() when popped off the stack.

If anyone has any insight into this behavior I would be most appreciative, because of the structure of the application as it stands now (it is slated for re-factoring, but that will take some time...) it causes me great problems in the application...


Sean Overby
    Bookmark Topic Watch Topic
  • New Topic