-2

I'm curious if it's possible to trigger a specific piece of code when a REST API its values changes. Actually a sort of realtime update a mechanism.

If it's not possible, what's a better to do it? The idea is when I push on a button (on my android device) a text will appear in a game (Java Desktop).

Thank you!

Snics
  • 3
  • 2

3 Answers3

0

Your question is not clear please rephrase it.

As you said you want that has to be done realtime.

Possible three approaches:

In android there are connection APIs with which you can connect your desktop(must have WiFi enabled) with phone. Then you can send or receive files and messages directly.

The other way is to have Push notifications but it's not guarantees realtime fast some time gets delayed otherwise performs good always.

Other way is to keep the connected socket open for listening changes from phone side to desktop side once connected but it's more costly.

Hope this gives you a direction, rest you can search over internet.

MobileEvangelist
  • 2,583
  • 1
  • 25
  • 36
0

Why not just make a simple setter? When you get a rest command to update something (for example some int value) you can do:

public void setValue(int newValue)
{
     value = newValue;
     doAction(newValue);
}

define the doAction as you want

CodeMonkey
  • 11,196
  • 30
  • 112
  • 203
0

If you need asynchronous update, use the thread. Learn multithreading Check the link to see if your requirement could be completed with the java thread concepts. http://www.javatpoint.com/multithreading-in-java

ajith george
  • 538
  • 1
  • 5
  • 14