Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6993825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:48:49+00:00 2026-05-27T19:48:49+00:00

Following is an onclick method called when a button is clicked. But the code

  • 0

Following is an onclick method called when a button is clicked. But the code doesn’t stop my application. It sends a message and then closes and then restarts again.. I have read the lifecycle model of an activity and fyi this is a single activity application. I also researched on stackoverflow, many of the post describing to have a return statement after finish() call so i have done that too but no results.

Where am i going wrong ???

public void onClick(View v) 
    {       
        String text = "Demo Message";

        String number = <set via a particular code>;


        if(number.equals(""))
        {
            Toast.makeText(this, "Please Enter or Select a Number", Toast.LENGTH_SHORT).show();
        }
        else
        {
            sms = SmsManager.getDefault();
            PendingIntent sentIntent = PendingIntent.getActivity(this, 0,
                new Intent(this, Main.class), 0);

            sms.sendTextMessage(number, null, text, sentIntent, null);
            Toast.makeText(this, "Message Sent to : " + number, Toast.LENGTH_SHORT).show();

            // Stop the Activity...
            finish();           
            return;
        }   
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T19:48:50+00:00Added an answer on May 27, 2026 at 7:48 pm

    Everything is quite simple. Your PendingIntent calls Main activity after sending sms. So the process is the following:

    1. Your application sends sms
    2. After that activity is finished
    3. But PendingIntent runs this activity once again

    You can simply test this by inputting in the onCreate() method log task, for instance Log.d("MyApp", "onCreate()"); and you’ll see that it is called after your sms is sent.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following code updates a set of progress bars when a button is clicked.
i creating for stopwatch with start,stop i use following code it started but not
The following code generates this error message at the public void onClick line. Multiple
I have the following code called when a button is pressed in my activity.
Say I have the following code: <div onclick='location.href=http://www.example.com/'> <a href='#' onclick='alert(blah)'>click</a> </div> Is there
I have mentioned the following in the onClick() method: Ibutton1.setColorFilter(Color.argb(150, 155, 155, 155)); //
I have the following scenario: At onClick() event 2 javascript functions are called, each
The following div's are displayed onclick. How can I make it display a different
This seems deceptively simple. How do you override the onclick event in the following
I have the following var id='123'; newDiv.innerHTML = <a href=\#\ onclick=\ TestFunction('+id+', false);\></a>; Which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.