PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, July 11, 2022

[FIXED] How to get back a reply through a message in Android activity

 July 11, 2022     android, android-activity, java, messages     No comments   

Issue

How can I get back a Message reply to the Activity in Android? Say an Activity ask one of a java object (Running Thread) to do something and give back the reply. How java object can know to reply back to the activity who sent the message? I have many activities and many objects communicate with each other.
How can I implement this with Android Messages? I don't want to use broadcasting here.


Solution

We can use Messenger for this. Can set the messenger as the reply path. And inside message it hold the handler it should give back the reply.

final Messenger messenger = new Messenger(handler); 
. 
.
msg.replyTo = messenger;  // set the handler of the reply activity.
msg.setData(mBundle);     // if any additional data available put to a bundle
destinationClass.mHandler.sendMessage(msg);



// in destination class

Messenger msger = msg.replyTo;  // get the message sender's details.

Message msg2 = Message.obtain();
msger.send(msg2);                // send the reply message again to the sender


Answered By - user2771655
Answer Checked By - David Goodson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing