Proper way to finish an activity

by DroidBy » Wed, 31 Mar 2010 16:10:30 GMT

Sponsored Links
 I think someone here can anwer me..

I have an application with 3 activities, A, B and C.
Three points here:-
1. In normal user sequence, activity A will start activity B, activity
B will then start activity C.

2. In case, user is also allowed to cancel activity B (by a button),
and it will resume back to activity A.

3. If activity B is interrupted by any application which comes into
foreground, activity B should be killed and user should start from
activity A if user navigate back to my application.

In point 2, I have called finish() if user click on the button;

In point 3, I have called finish in activity B onPause() function

End up, I get an warning saying that I have duplicate finish request
by Activity Manager as in point 2, the onPause() will be called also.

So, does anyone here no how should I do in handling for point 2 so
that I am able to resume to activity A after user cancels activity B?
Or how should I do in case to stop my activity B so that user always
start from activity A?

Any best advise here?


Proper way to finish an activity

by Peter Fortuin » Wed, 31 Mar 2010 16:23:58 GMT

 Hi DroidBy,

Maybe it's a good idea to read the following: #actlife
Read the part about the Activity lifecycle. That should answer your

Kind regards,


2010/3/31 DroidBy <>


Sponsored Links

Proper way to finish an activity

by DroidBy » Thu, 01 Apr 2010 10:06:36 GMT


I read that before. But it still can't solve my problem in point 2.

As if I call finish during onPause(), then I will have duplicate
finish request complaint by the ActivityManager if user clicks on the
<Cancel> button which will call finish() , and then the activity will
enter into pause state and call finish() again.


> >

Proper way to finish an activity

by DroidBy » Thu, 01 Apr 2010 11:51:43 GMT

 Hi Peter,

Ya, by implementing some flags, I manage to see if I should call
finish in the onPause state.
Now my problem is resolved.


> > >

Other Threads

1. Compile and port Android os in MS104-SH4AG board

Any English information, I cannot read japanese.

I've never worked with SH4, and I don't know if android stands for that

But anyway you can start here:,1001893


2. how to use jmdns

My goal is to find network printers using jmdns

Following is the code I have written which does not work. I am new to
all this Pls. help me.
What exactly I want to do is to list all printers in list
box...Currently I am not filtering printers..

I am always getting exception... Here is my code

public class ListPrinters extends ListActivity {
        public static JmDNS jmdns;
        public static JmDNSImpl impl;
        protected ServiceListener listener;
        protected ServiceInfo info;

        public ListView lv;
        public ArrayList<String> PrinterList;
        public int cancel =0;

        public final static String TAG = "ListPrinter";

        /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {

        PrinterList = new  ArrayList<String>();
        PrinterList.add("First Node");   /// just for checking
                setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1 , PrinterList));
                lv = getListView();
                 lv.setOnItemClickListener(new OnItemClickListener()
                         public void onItemClick(AdapterView<?> parent, View 
                                         int position, long id)
                                 // When clicked, show a toast with the 
TextView text

                                 if (jmdns != null)

                                         ListPrinters.jmdns = null;
                                         ListPrinters.impl = null;


        this.listener = new ServiceListener() {

                                public void serviceAdded(ServiceEvent event) {

                                        PrinterList.add("Service added   : " + 
event.getName() + "." +
                                        Log.v(TAG,"Service added   : " + 
event.getName() + "." +

                                public void serviceRemoved(ServiceEvent event) {
                                        PrinterList.add("Service removed : " + 
event.getName() + "." +
                                        Log.v(TAG,"Service removed : " + 
event.getName() + "." +

                                public void serviceResolved(ServiceEvent event) 
                                        PrinterList.add("Service resolved: " + 
                                        Log.v(TAG,"Service resolved: " + 



        public void showAllPrinters()
            ListPrinters.jmdns = JmDNS.create();
            ListPrinters.impl = (JmDNSImpl)jmdns;

        catch (IOException e)



3. Broadcast receivers

4. Beginner Question: Is it possible to put each class into it's own java file in Eclispe?

5. Could anyone with an HTC Desire/Droid help me

6. Modify strings.xml dynamically

7. Weird: It appears as if sometimes my Activity will be resumed but previously set instance variables are null