In my application i want to check any new orders are there for every 5 minutes.if any new order came,i want to show alert box in any activity of my app and if the app is in back ground(not visible) i want to show notification
Asked
Active
Viewed 43 times
-3
-
what should i use service or intent service, and in that what should i use to load data from web. – shra1 Nov 04 '16 at 17:17
-
How often are you expecting orders to come? If it isn't very often, you might want to take a look at Firebase Cloud Messaging, and arrange for the server to inform the app when an order arrives - it will use less battery – Eugene Styer Nov 04 '16 at 17:37
-
for every 5 minutes i want to check the new order, and do not want to use Firebase cloud messaging. – shra1 Nov 05 '16 at 05:31
2 Answers
0
A service class with scheduler with fixed rate of time is better to do and for contacting with main ui use result receiver.

shra1
- 1
-1
You can use Service, Thread for it, or you can make it in the Activity (not good). In the Service/Thread/Activity use a CountDownTimer or sleep() with an infinity while loop. So:
boolean b= true;
CountDownTimer cd = new CountDownTimer(3*60*1000, 1000) {
@Override
public void onTick(long millisUntilFinished) {
//Nothing comes here
}
@Override
public void onFinish() {
//Here comes the server request
}
};
while(b){
cd.start();
}
or so:
boolean b= true;
while(b){
//Here comes the request
try {
Thread.sleep(3*60*1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
Thease methods are going to work, but thease are going to use a lot of energy, so be carefull with them.

csillagu
- 21
- 6
-
without consuming lot of energy, and i want to start downloading the content as soon as service starts and want to show alert box in the currently opened screen of my app, if the app is in background i want to show notification, so please understand clearly. – shra1 Nov 05 '16 at 05:27