Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
224 views
in Technique[技术] by (71.8m points)

java - Is there anyway to put complete message after startActivity()?

(Oh, first of all, I'm sorry for my bad English)

Hello~!

I just started to learn android programming.

I tested sending an intent object with "text/plain" to messenger app and checked it worked properly.

After sent the intent object completely, I could see a toast-like message box like below(orange one).

enter image description here

I want to add some confirm message like 'message sent' to that toast-like message.. What should I do?

Thank you.

Updated

Here's my code.

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}

public void sendMessage(View view) {
    EditText editText = findViewById(R.id.message_edit);
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("text/plan");
    intent.putExtra(Intent.EXTRA_TEXT, editText.getText().toString());

    if(intent.resolveActivity(getPackageManager()) != null) {
        startActivity(intent);
    }
}

}

and this is the build.gradle setup of module.

compileSdkVersion 29

defaultConfig {
    applicationId "com.example.actionsendexam"
    minSdkVersion 21
    targetSdkVersion 29
    versionCode 1
    versionName "1.0"

    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

Once again, thank you for reading my question.

question from:https://stackoverflow.com/questions/65887524/is-there-anyway-to-put-complete-message-after-startactivity

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can use Toast message

You can use like :

Toast.makeText(this, "Message Sent", Toast.LENGTH_SHORT).show()

If you put this code after what you want to do, you can see the toast message with the text.

Also if you want to check the detail, you can check Android official document

If you have any problems, please leave a comment.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...