kodi1911
kodi1911

Reputation: 722

Android: go back to activity, after using intent with sms

First of all, link to the project and ling to the used fragment and used activity. I've got a problem with going back to the DrawerActivity, after using intent for sending a sms. I'm launching the intent from the TimetableFragment in the listview onItemLongClick listener and then it's going do use the method sendSms in the DrawerActivity

listTrainLeftLstView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener(){
               @Override
                public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l){
                    Toast.makeText(getActivity().getApplicationContext(), "Long press", Toast.LENGTH_SHORT).show();

                    //selected stations
                    String stationFrom = startIdSpinner.getSelectedItem().toString();
                    String stationTo = endIdSpinner.getSelectedItem().toString();

                    //selected item
                    Train selectedItem = (Train) adapterView.getItemAtPosition(i);
                    String selectedTime = selectedItem.hour + ":" + selectedItem.minute;
                    String direction = selectedItem.tip;

                    //send sms (communication fragment -> activity)
                   mCallback.sendSms("heheszki");

                    return true;
               }
            });

It works, I can send the sms, but after sending it don't go back to the DrawerActivity - it still sits in the sms intent. Also if I use the back button it's going to close my app.

Implementing solution with onCreate method is going to crash my app at the start, and using onActivityResult is going to pass:

resultCode = 0

The expected result is to go back to DrawerActivity after sending the sms, and go back to the DrawerActivity while pressing Back button in the sms intent.

Upvotes: 2

Views: 672

Answers (1)

Sharath
Sharath

Reputation: 691

Once to switch to another activity the previous activity will be cleared from the stack.try finish() so that it gets back to previous activity.

Upvotes: 1

Related Questions