user2617241
user2617241

Reputation: 11

How to use same android button to start an activity and do a function in previous activity?

I have an SMS application.Here i wish to use the send button to send sms in that activity as well as move on to new activity.I have written code to send sms.But dono how to go to another activity at the same time.Kindly help.This is the code.

btn.setOnClickListener(new View.OnClickListener() {     

                @Override
                public void onClick(View arg0) {

                    String mobileno=pno.getText().toString();
                    String text=msg.getText().toString();
                    sentsms(mobileno,text);

                }

            });

Upvotes: 1

Views: 36

Answers (3)

selva_pollachi
selva_pollachi

Reputation: 4217

Try this..

  btn.setOnClickListener(new View.OnClickListener() {     

        @Override
        public void onClick(View arg0) {

            String mobileno=pno.getText().toString().trim();
            String text=msg.getText().toString().trim();
            sentsms(mobileno,text);

            Intent intent = new Intent(this, YourActivityName.class);
            startActivity(intent);
        }

 });

Upvotes: 0

Suji
Suji

Reputation: 6044

Please look at the code below:

btn.setOnClickListener(new View.OnClickListener() {     

                @Override
                public void onClick(View arg0) {

                    String mobileno=pno.getText().toString();
                    String text=msg.getText().toString();
                    sentsms(mobileno,text);

                    // start other activity here
                    Intent intent = new Intent(CurrentActivity.this,
                        YourOtherActivity.class);
                    startActivity(intent);

                }

            });

Upvotes: 1

FD_
FD_

Reputation: 12919

Use something like this:

Intent intent = new Intent(this, YourSecondActivity.class);
startActivity(intent);

In your onClick, this would be:

btn.setOnClickListener(new View.OnClickListener() {     

            @Override
            public void onClick(View arg0) {

                String mobileno=pno.getText().toString();
                String text=msg.getText().toString();
                sentsms(mobileno,text);

                Intent intent = new Intent(this, YourSecondActivity.class);
                startActivity(intent);
            }

});

Upvotes: 1

Related Questions