I am quite busy with a new application. However I created a service which calls a method like this:
MessageProcessor mp = new MessageProcessing(MessageService.this);
wa.setNewMessageBind(mp);
However since it's added into a service instead of an Activity this error shows up:
nl.giovanniterlingen.whatsapp.MessageService cannot be cast to android.app.Activity
And yes, I searched a lot on the internet, but still I couldn't find an answer that fits my need. Here is the MessageProcessing source:
((Activity) context).runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(
context,
msg.getFrom() + "(" + msg.getGroupId() + "): "
+ msg.getText(), Toast.LENGTH_SHORT)
.show();
}
});
When I replace the toast with system.out
like this:
System.out.println(msg.getFrom() + "(" + msg.getGroupId()
+ "): " + msg.getText());
Then it's working fine, but I want a toast so that's why I am asking.
For a more clearer view see my Github and the latest commits from 09-07-2015