Monday, 23 October 2017

Schedule Android Background Job Using Firebase JobDispatcher

From Android version 8.0 (Oreo) on wards there are limitations in executing background services and there are some limitations in receiving certain broadcasts. The android team implement all these restrictions to improve app performance and device battery life. If your app target API 26 then you have to consider some other mechanisms to do your background job. 
Fortunately there is JobScheduler API that solve the problem regarding the background job limitations in newer versions of android. Google suggests Android App developers to use the JobScheduler API for their background job execution rather than using a background service. 

But the problem is that the android framework JobScheduler API is available from android API version 21(Lollipop) and above. If your app support start from Lollipop and above then you can go for the framework JobScheduler API for your background job.


If your App support start from android API lower than 21 then you can use the Firebase JobDispatcher for performing your background operations. 



  • Firebase JobDispatcher API is available from Android API 9 and above. 
  • It uses the Android framework Job Scheduler API features for its operations. 
  • It needs google play service installed in the device.



So here we are going to create an Android example of how to use firebase JobDispatcher in your android application. 

 Step 1:
 Add the latest dependency for using firebase JobDispatcher in your android application. Open your android studio project module level gradle file and add the following dependency in the dependencies section. 
             
    "compile 'com.firebase:firebase-jobdispatcher:0.8.4'"

You can check here for the latest dependency. 

Step 2 :
Implement the job service class for defining your job. Create a new java class that extends JobService and implement the needed methods.

Here is the implementation of Firebase JobDispatcher JobService.


 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
public class MyService  extends JobService{

BackgroundTask backgroundTask;

@Override
public boolean onStartJob(final JobParameters job) {

backgroundTask = new BackgroundTask()
{
@Override
protected void onPostExecute(String s) {
Toast.makeText(getApplicationContext(),"Message from Background Task :"+s,Toast.LENGTH_LONG).show();
jobFinished(job,false);
}
};

backgroundTask.execute();
return true;
}



@Override
public boolean onStopJob(JobParameters job) {
return true;
}


public static class BackgroundTask extends AsyncTask<Void,Void,String>
{

@Override
protected String doInBackground(Void... voids) {
return "Hello from background job";
}
}


}
  
In JobService class you need to implement two methods, onStartJob and onStopJob.

You have to place your job within the onStartJob method. The job service is executed on the main process thread, so if your job is a time taking one ( for example download a large file from server), then you have to run the job on a separate thread, otherwise the system may issue an Application Not Responding dialog.


In the above example i uses an AsyncTask for performing the background task. The AyncTask has a separate worker thread for the job.

Ads By Google

  • The return type of the onStartJob is a boolean. 
  • If you use a separate background thread for the job execution, then you have to return true from the onStartJob method. 
  • If you return true then you must call the method jobFinished() soon after the job finishes.  
  • jobFinished method needs two parameters, Job parameters and a boolean value. 
  • If you want to reschedule the same job again, then you can pass true as second parameter. 
  • If you forget to call the jobFinished() method, then the system assume that your job is still running in the background and that cause the JobService to run without any task and that leads faster battery drain.
  • If the task interrupted before finish, then the system call the onStopJob() method. You can clear all the unfinished job resources from here. If you want to reschedule the interrupted job again then you have to return true from this method.    

Step 3 :
Register the Job Service in Manifest file. Open your application AndroidManifest.xml file and add the following code in the application tag.


1
2
3
4
5
  <service android:name=".MyService">
<intent-filter>
<action android:name="com.firebase.jobdispatcher.ACTION_EXECUTE"></action>
</intent-filter>
</service>

Job service is ready and now you can schedule the job.

Step 4 :
Start (Schedule) the job.
Here is the code segment that schedule the job.


 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
 public void startJob(View view)
{
String Job_Tag = "my_job_tag";
FirebaseJobDispatcher jobDispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(this));
Job job = jobDispatcher.newJobBuilder().
setService(MyService.class).
setLifetime(Lifetime.FOREVER).
setRecurring(true).
setTag(Job_Tag).
setTrigger(Trigger.executionWindow(10,15)).
setRetryStrategy(RetryStrategy.DEFAULT_EXPONENTIAL).
setReplaceCurrent(false).
setConstraints(Constraint.ON_ANY_NETWORK)
.build();
jobDispatcher.mustSchedule(job);
Toast.makeText(this,"Job Scheduled..",Toast.LENGTH_SHORT).show();

}
   

  • To schedule a job first you have to create an object of FirebaseJobDispatcher class.
  • You have to pass the GooglePlayDriver object to the constructor of FirebaseJobDispatcher.
  • You can create Job class object by calling the build method on JobBuilder.   
  • The job parameters are specified on the JobBuilder object. You can get the JobBuilder object by calling the newJobBuilder method using the FirebaseJobDispatcher object. 
  • setService() : Through this method you can specify the Job Service class in which you place your job. 
  • setLifeTime(): Specify the life span of the job. Default value is Lifetime.UNTIL_NEXT_BOOT
  • setRecurring() : Specify whether the job repeat or not. 
  • setTag() : Help the system to uniquely identify the job using its tag.
  • setTrigger() : Specify the job start time an repeating interval.
  • setRetryStratergy() :  Specify retry with exponential back off
  • setReplaceCurrent() : Specify whether or not replace the job having same tag. 
  • setConstraint() : Specify the job requirements. For example Constraint.ON_ANY_NETWORK (Run on any network), Constraint.DEVICE_CHARGING(Only run when device is charging) etc.   
  • Finally you can schedule the job by passing the job as a parameter to the mustSchedule method. 
  • You can call the mustSchedule method on the JobDispatcher object. 

Cancelling A Job : 
  • To cancel a particular job call the dispatcher.cancel('job Tag') method. 
  • To cancel all the jobs call dispatcher.cancelAll() method. 
Conclusion:
Firebase job dispatcher is the best choice for running background task in your android application from Android API version 9 and above. I hope you understand all the concepts. 

Sunday, 22 October 2017

Plant vs Zombie 2 Mod For all Versions By Game Killer

Plant vs Zombie 2 Mod By Game Killer


👇FEATURES OF THIS HACK👇

(1) UNLIMITED GOLD

(2) UNLIMITED GEMS

(3) ALL PLANTS UNLOCKED

(4) NO ROOT

(5) Game Killer MOD ENABLE


👉How To Used👈

DOWNLOAD THE SAVE DATA AND THEN EXTRACTE IT THEN YOU CAN GET A FOLDER CALLED [PLANT VS ZOMBIE MOD BY GK] INSIDE THE FOLDER YOU CAN GET MAIN FOLDER CALLED [com.ea.game.pvz2_row] THEN COPY THE FOLDER AND PEST IN Android/data FOLDER AND THEN ENJOY THE UNLIMITED HACK


To Luarn How To Hack Any Games Subscribe Hack Now Channel


8 Ball Pool Mod v3.11.2 By Game Killer

8 Ball Pool Mod v3.11.2 By Game Killer


👇FEATURES OF THIS HACK👇

(1) UNLIMITED HEALTH

(2) ANT BAN FOR 1 week

(3) UPDATED VERSION

(4) NO ROOT

(5) Game Killer MOD ENABLE


To Luarn How To Hack Any Games Subscribe Hack Now Channel


Friday, 20 October 2017

Argentina football team Fifa world cup 2018 Russia (official ) - qualifi...

Picking Argentina's 2018 World Cup Squad After Latest International Games

Goalkeepers


    Sergio Romero is the established No. 1 and will continue to be so for the 2018 qualification period and finals, by the end of which he'll be approaching or possibly just past a century of caps for the national team...which isn't bad, considering he's only a back-up at club level.
    Nahuel Guzman is the usual deputy, and the UANL stopper should go as No. 2, with his CONCACAF Champions League performances adding experience to his armoury.
    Third, and showing a little faith here, we're opting for Geronimo Rulli.
    In truth the 24-year-old is uncapped for a reason: Although he's tremendously athletic, has great reflexes and has a big reputation, his mistakes are costly and frequent, and his judgement is still lacking. Even so, playing three successive seasons in La Liga will continue to refine his game, and he's still the most likely heir to Romero's spot—and the only goalkeeper in consideration under 30 years of age

Full-Backs


    Four full-backs for Argentina, boasting plenty of experience between them...if not quite as much offensive class and exciting thrust as some of the real challengers for the World Cup have in their own squads.
    Pablo Zabaleta will still be around and in place on the right, and he'll be challenged for the spot by Sevilla's Gabriel Mercado. Aggressive, taller than Zabaleta and two years younger, it could well be that Mercado is the starter on that side of defence.
    On the left, expect Marcos Rojo to line up even though it's clearly not his favoured position. He still has the aggression to lock down that side of defence, has reasonable recovery pace and won't be shy about trying to get forward in support, but his overall game is certainly a level lower when on the side of defence compared to in the middle.
    Challenging Rojo for left-back—or standing in for him when suspended, perhaps—we're going for Emmanuel Mas, currently with Trabzonspor and who has played his part in the qualifiers so far.

    Centre-Backs

      Argentina have habitually had a couple of decent centre-backs to pick from, but pairing them up for any length of time seems to have been a real problem over the last few tournaments.
      We're anticipating Nicolas Otamendi recovers enough form to take his place as the defensive leader; aggressive on the front foot and covered in beard, shouting positional instructions he's all too keen to ignore himself when there's a challenge to be made outside the box.
      Alongside him, it's a little bit take-your-pick.
      Everton's Ramiro Funes Mori is our best guess to start the tournament in the back four, but it may well come down to form or simply finding the winning partnership. Who complements Otamendi best, dropping in behind and sweeping up the loose balls.
      If it were down to pure quality, Mateo Musacchio would be in the XI, but injuries have taken 20 or 30 caps off him already, and the Villarreal man still has a lot to prove at this level.
      Fourth choice will be Facundo Roncaglia, but it comes with a caveat: Ezequiel Garay hasn't played for Argentina for two years, but if he finds form and shines for Valencia, he could well make a crashing late entrance not just to the squad, but to partner Otamendi.

      Midfielders

        Six midfielders for Argentina, starting with the immovable rock, the must-have, the organiser, the protector and no doubt at times the last-ditch saviour: Javier Mascherano.
        A centre-back at club level, Mascherano nonetheless reprises his defensive-midfield role on the international stage and remains one of the world's finest, with his unstoppable will to win and non-stop aggression setting the tone for the rest of the team to match.
        Alongside him in the middle there will be one of three, each capable of working hard defensively but also being the metronomic distributor from the centre circle and from higher upfield: Lucas BigliaEver Banegaand Augusto Fernandez.
        Depending on how Argentina line up—Bauza has used both 4-3-3 and 4-4-2 variations, with wide, high, inside forwards in the latter—there could be different roles for Angel Di Maria, but he'll certainly be in the XI either way.
        And, finally, we opt for the wiles and too-often-hidden genius of Javier Pastore to convince the boss he's worth a plane ticket.

        Forwards

          First and foremost, suspended or not, Lionel Messi is in.
          Then there will be the out-and-out strikers, and with no Maurco Icardi in sight it's the usual duo of Gonzalo Higuain and Sergio Aguero who will be travelling. Both have played from time to time, either when Messi doesn't or with one deeper than the other through the middle and Messi wide, but more often than not we'd expect one to start, one on the bench.
          If Messi's absence during qualification teaches Argentina one important lesson, it could well be that Paulo Dybala is going to be almost as important over the next decade. One or two big performances from him in the blue and white and he'll be a cert for the squad, and maybe a consideration to start.
          Then it's the big decision over which players will offer most either as wide starters, or off the bench as impact subs. The experience of Nico Gaitanremains, and we're betting that a club team-mate at Atletico Madrid really steps up a level over the next 12 months, meaning Angel Correa takes the final place in our squad.
          Argentina's 23 is, once again, a group that gets markedly stronger as it moves upfield, but there's certainly enough quality there to be confident of reaching the latter stages once more.
          Are there the match-winners to go all the way this time? Can they end the run of being losing finalists year after year? It's a tough ask, but with Messi anything is possible—now all they have to do is qualify without him.

          Missed the Plane

            Naturally, where 23 are happy, a further group will be inherently disappointed to miss out, and we've got seven such names to frustrate.
            Goalkeeper Mariano Andujar has been a squad regular, but aged 35 by the time the World Cup finishes and only having played once in the last two years at international level, he's not going to add enough. He stays at home.
            Similarly, Martin Demichelis cannot be included merely for experience when four of the squad's defenders will already be in their 30s. Lacking pace and unlikely to feature after the finals, it's time for the former Bayern Munich and Manchester City man to step aside.
            In midfield it's a blow for La Liga men who simply won't see enough game time: Matias Kranevitter has yet to impress consistently since moving to Atletico Madrid, including on loan at Sevilla this term, while Enzo Perezcaptains Valencia but misses out with frequency to injury or suspension. With another rebuild on the cards this summer for Los Che, we're betting Perez is too inconsistent to make the cut.
            Further forward, Erik Lamela has been a big part of Argentina's squad in the last year or two, but there's such competition in the final third that when push comes to shove, we'd leave him aside.
            Ezequiel Lavezzi is ageing, unimpressive and unnecessary in the squad, and while we can find very little fault with Mauro Icardi and his game at Inter Milan, he simply doesn't seem fancied by the Argentina management. We can't, therefore, predict he'll be on the plane.

Sunday, 15 October 2017

Mini Military Rapid Fire Mod by Game Killer

Mini Military Rapid Fire Mod by Game Killer


👇FEATURES OF THIS HACK👇

(1) UNLIMITED HEALTH

(2) RAPID FIRE

(3) 7X ZOOM FOR ALL GUNS

(4) PRO MOD UNLOCK

(5) UNLIMITED GAS BOMB AND TIME BOMB

(6) NO ROOT

(7) Game Killer MOD ENABLE


To Luarn How To Hack Any Games Subscribe Hack Now Channel