YEah,

Why are you calling finish from onPause method?  It will finish you
application, even when you would not want it to.

Try this. On a specific event, set the result and just call finish. That
should do.

Kumar Bibek
http://techdroid.kbeanie.com
http://www.kbeanie.com



On Wed, Dec 22, 2010 at 4:14 PM, pramod.deore <[email protected]>wrote:

> Hi I have one activity which invoked another activity
>
> roomIntent.putExtra("roomName",roomNM );
> roomIntent.setClass(AddScheduler.this,RoomList.class);
> startActivityForResult(roomIntent,Room_SELECT);
>
> protected void start(Intent intent)
>        {
>                this.startActivityForResult(intent,Room_SELECT);
>        }
>
>        protected void onActivityResult(int requestCode, int resultCode,
> Intent data)
>        {
>                System.out.println (requestCode);
>
>                switch(requestCode)
>                {
>                        case Room_SELECT:
>
>                                System.out.println (resultCode);  //here it
> returns 0
>                                 if (resultCode == RESULT_OK)
>                                {
>                                        ...........
> //Because result code returns 0 therefore this if conditio does not
> execute.
>                                }
>                }
>
>        }
>
> And here is my other activity which returns result.
>
> public class RoomList extends ListActivity
> {
> super.onCreate(savedInstanceState);
>        Bundle extras = getIntent().getExtras();
>        if(extras !=null)
>        {
>                value = extras.getString("roomName");
>                sw = getSwitchNameArray(value);
>        }
>        setListAdapter(new ArrayAdapter<String>(this,
>                android.R.layout.simple_list_item_multiple_choice,
> sw));
>        final ListView listView = getListView();
>        listView.setItemsCanFocus(true);
>        listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
>
> listView.setOnItemClickListener(new ListView.OnItemClickListener() {
>
>                        @Override
>                        public void onItemClick(AdapterView<?> arg0, View
> arg1, int arg2,
>                                        long arg3)
>                        {
>                                // TODO Auto-generated method stub
>                                System.out.println ("User checked boxes");
>
>                                if (listView.isItemChecked(arg2))
>                                {
>                                        System.out.println
> ("###"+listView.getItemAtPosition(arg2));
>                                        room = (String)
> listView.getItemAtPosition(arg2);
>                                        selectedRooms.add(room);
>                                        System.out.println ("Size
> is"+selectedRooms.size());
>
>                                }
>
>                                else
>                                {
>                                        String str = (String)
> listView.getItemAtPosition(arg2);
>                                        selectedRooms.remove(str);
>                                        System.out.println ("Size
> is"+selectedRooms.size());
>                                }
>                        }
>
>
>        });
>
> @Override
>        protected void onPause()
>    {
>        super.onPause();
>
>        System.out.println ("User click on back button");
>
>        mySwitches = new String[selectedRooms.size()];
>        selectedRooms.toArray(mySwitches);
>        int str = mySwitches.length;
>        System.out.println ("!...@#!@#...@#"+str);
>        Intent returnIntent = new Intent();
>        //returnIntent.putExtra("SelectedSwitches",selectedRooms);
>        returnIntent.putExtra("SelectedSwitches", str);
>        setResult(RESULT_OK,returnIntent);
>        System.out.println ("Before calling finish");
>        finish();
>        System.out.println ("After calling finish");
>        }
>
>  public String[] getSwitchNameArray(String rn)
>    {
> ......returns string array
> }
>
> I think in resultCode I get 0 because I write
> setResult(RESULT_OK,returnIntent);  inside onPause () method. Or there
> is another problem? I had write that inside onPause bacause in this
> activity I am calculating name of selected items. And I never knows
> when user had finished selecting items. After writing code inside
> onPause I know what item user had selected from list and I can pass
> them to the calling activity.
>
> I think better approach is to add one button means suppose user click
> on save button then selected item will be sent to the calling
> activity. Want your opinion? where should write code. If it doesn't
> affect write inside onPause() then why I got 0 from resultCode.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]<android-developers%[email protected]>
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to