Problem in going in back/previous activity

by Komal » Tue, 10 Feb 2009 12:05:30 GMT

Sponsored Links
I am developing simple application.
I have one activity which displays list of name of employees. I m
fetching the employees name from database.
when i click on any of the name ,i will display the next page showing
details of that employee. also fetching details of employee from the
It is working perfectly.
but when i press back button of android phone to go back to the
list ,i m facing an error.
how can i go back to the list?
please help me!!

Problem in going in back/previous activity

by Komal » Fri, 13 Feb 2009 12:50:24 GMT

 No one can solve my problem!!!!somebody please help me!!!!


Sponsored Links

Problem in going in back/previous activity

by Sundog » Fri, 13 Feb 2009 23:20:29 GMT

 If your two activities are calling and returning properly, check your
first activity's onResume() function for something screwy. At least
put a log statement there to tell you if it even gets that far. Might
do the same with the second activity's onPause() too.


Problem in going in back/previous activity

by Sundog » Fri, 13 Feb 2009 23:33:02 GMT

 To expand on that, I had exactly this problem and found that my first
activity's onResume() was indirectly reinitializing something it
shouldn't have, and kaboom.


Problem in going in back/previous activity

by Komal » Mon, 16 Feb 2009 10:51:33 GMT

Thnx  for  replying.
Its calling onPause() method of second activity but its not calling
onResume() of first activity. why it is so??
This is my code for calling next activity

protected void onListItemClick(ListView l, View v, int position, long
id) {
                super.onListItemClick(l, v, position, id);
                Intent i = new Intent(this,WebViewData.class);
                //int clickedposition=(mypos-15) + position;
                int clickedposition=(15 * clicks) + position;


i am not using finish() in my second activity because if i call finish
() then its just going in that activity  and coming back in previous
activity, not displaying the details of second activity.

and another thing is,,

In my onResume() of first activity i am calling on function which
displays the employee list using setListAdapter(new IconicAdapter
(MoreData.this))..where  i am overriding getView() method.

as i m just displaying the details of  employees in my second
activity, there nothing(any field or variable or anything) which is
related to previous activity which i can save in onPause() of second
what should i write in my onPause() method of second activity.
I had a look at Notepadv3 Application of google,,they are saving
mRowID and inserting or updating data.i am not doing anything like
this,,i m just displaying information..then what should i write in my

As i am  new to android, may be i misunderstood some concepts, please
help me!!!
Thnx in advance,


Problem in going in back/previous activity

by Greg Krimer » Mon, 16 Feb 2009 15:43:56 GMT

 ransitioning to a previous activity via the Back hard-key should be
handled by Android for you (unless you are capturing the Back key
event yourself, which does not sound like what you are doing because
onPause() of your second activity is getting called). The only way I
have screwed this up is when I had errors in my Activity callbacks
that prevented the activity from running, as mentioned by Sundog. Have
you checked the logs (adb logcat or DDMS) for any exceptions thrown
when you transition from your second activity to your first? What
exactly happens when you hit the Back button from your second
activity? What do you see on the screen when you press the Back

On Feb 15, 6:51pm, Komal <> wrote:

Problem in going in back/previous activity

by Komal » Thu, 19 Feb 2009 08:10:10 GMT

Thnx for replying.
when i am pressing back button ,it is throwing exception,,
in my Logcat,,

Java.lang.RuntimeException:Unable to resume activity {android.myempapp/
android.myempapp.MoreData}: java.lang.IllegalStateException : attempt
to acquire a reference on a close SQLiteClosable}

and on phone it is saying

The application Emp Application (process android.myempapp) has
stopped unexpectedly.Plese try again.

I cant understand what it mean to say..


On Feb 16, 6:43pm, Greg Krimer <> wrote:

Problem in going in back/previous activity

by Sundog » Fri, 20 Feb 2009 01:52:23 GMT

 ou closed your database - probably on the activity exit -  and
subsequently tried to access it. Been there, done that! ;)

On Feb 18, 5:09pm, Komal <> wrote:

Problem in going in back/previous activity

by Komal » Tue, 24 Feb 2009 09:48:51 GMT

The Problem is solved, I am posting the solution because some body may
face same problem and need solution.
In my app i am using startManagingCursor(c) for managing cursor,,so
the method handles all functions of cursor,,i doesn need to close
the cursor.
I have removed all c.close() from my app ,,and now my app is running

Thanx to all for help.

On Feb 20, 4:52am, Sundog <> wrote:

Problem in going in back/previous activity

by Jeffrey Yasskin » Sun, 08 Mar 2009 07:33:33 GMT

  ran into this problem too, and in my case it wasn't so easy to go
find all of the c.close() calls since I hadn't written any. For the
next person who runs into this, it turns out that
SimpleCursorAdapter.changeCursor() will close the previous cursor (as
documented). So instead of calling changeCursor directly, you have to
first retrieve the previous cursor and stopManaging it. It would be
nice if the second step were explicitly in the documentation too.

I considered avoiding having the cursors managed at all, since the
Adapter takes responsibility for closing the cursors, but I suspect
the automatic .deactivate() and .requery() calls are useful for saving
resources when the Activity isn't in the foreground.

On Feb 23, 5:48 pm, Komal <> wrote:

Other Threads

1. Class derived from IntentService must have default constructor

I'm posting this to share the lessons I learned while working with

IntentService has a single constructor that takes a string argument
"name". The documentation has no description of what name is used for.
In looking at the sources, I found that its only use is in naming the
worker thread for the IntentService. This thread is named IntentService

I initially implemented the constructor of the derived class to also
take a String argument and passed it along to the derived class. This
is wrong. This will cause the startService() call to generated a
java.lang.InstantiationException in the application containing the
service i.e. you don't get the exception in the application calling
startService(). A clue to the actual problem is a little further up in
the logs:"newInstance failed: no <init>()"

The derived class must have a Default constructor and that constructor
must call super() passing a string for the name component of the
worker thread name.

public class MyIntentService extends IntentService
    public MyIntentService() {

    protected void onHandleIntent(Intent intent)
        // Handle events on worker thread here


2. Application gets killed due to a timeout


since Cupcake our application became very unstable. It often dies and
users have to restart it manually. The log shows that it was killed
due to a timeout, something like this:

W/ActivityManager(   56): Timeout of broadcast BroadcastRecord
{434824c8 android.provider.Telephony.SMS_RECEIVED} -
W/ActivityManager(   56): Receiver during timeout: ResolveInfo
{434663b8 p=0 o=0 m=0x108000}
I/Process (   56): Sending signal. PID: 4702 SIG: 9
I/ActivityManager(   56): Process (pid
4702) has died.

Previously it was working all fine. It also works fine on Emulator.
But it is extremely slow on HTC Magic. We found that sometimes it does
take some time to respond to some requests (such as the broadcast
above for Telephony.SMS_RECEIVED), while in other cases (for example,
we have a background Service which starts on BOOT_COMPLETED) it seems
the problem is not in our code. Previously, it was taking only 5
second for the service to start, while now it takes 15 seconds - the
same application, on the new Cupcake phone. I tried converting the
service onStart into a simple "new Thread().start()" - and guess what,
that gets killed as well before it reaches my first line of code. For
the cases when our code is "slow" it became much slower with Cupcake
(or is it HTC Magic?).

I guess I have two questions to Google, but if someone has workarounds
or similar experience please speak up:

1. Why is Cupcake so slow?
2. Can you document the expected time limits within which some
methods, either event listeners or overridden, should return before
they are considered timed out? We don't mind updating the application
by making sure we do respect those limits, but not knowing them costs
us too much money as we are discovering them through customer support
calls. The example methods which I suspect do have those limits are
Service.onStart, ContentObserver.onChange to name a few.



3. ListView inside LinearLayout inside ScrollView

4. things turning on in the night

5. why MotionEvent.ACTION_DOWN doesn't fire in onTouchEvent?

6. **never ever** use Toasts with Activity context

7. Android Maket Place Apps