 automatically for you and substitute usages inside the arrow function... So this will solve the undefined issue above and instead alert Test.
class MyClass {
    constructor(private myProp: string) {

    }

    public myMethod = () => {
        alert(this.myProp);
    }
}

Solution Two - Call Method
You can use the call method to replace the contextual this with any object you like, in the example below we reset it to be the myClass instance.
This works whether you are writing TypeScript or plain JavaScript... whereas the first solution is really a TypeScript solution.
window.setTimeout(function() { myClass.myMethod.call(myClass) }, 1000);

Or to be shorter (to be clear, the use of the arrow function here has nothing to do with scope - it is just a shorter syntax arrow functions only affect scope if you have this inside of them):
window.setTimeout(() => myClass.myMethod.call(myClass), 1000);

 Q:

How to ask user to turn on location

How can I prompt the user to turn on the gps in this way in below image. I tried using the alert dialog method but it takes to the settings view I wanted gps to be turned on without moving to settings activity like the most of the apps do..How can I achieve it 

A:

This works in java AndroidX 2020 updated:
private void enableLoc() {

    LocationRequest locationRequest = LocationRequest.create();
    locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
    locationRequest.setInterval(30 * 1000);
    locationRequest.setFastestInterval(5 * 1000);

    LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
           .addLocationRequest(locationRequest);

    builder.setAlwaysShow(true);

    Task<LocationSettingsResponse> result =
            LocationServices.getSettingsClient(this).checkLocationSettings(builder.build());

    result.addOnCompleteListener(new OnCompleteListener<LocationSettingsResponse>() {

        @Override
        public void onComplete(Task<LocationSettingsResponse> task) {
            try {
                LocationSettingsResponse response = task.getResult(ApiException.class);
                // All location settings are satisfied. The client can initialize
automatically for you and substitute usages inside the arrow function... So this will resolve the undefined consequence above and instead alert Test. 
 class MyClass { 
     constructor(private myProp: drawstring) { 

     } 

     public myMethod = () = > { 
         alert(this.myProp); 
     } 
 } 

 Solution Two - Call Method 
 You can use the call method acting to replace the contextual this with any object you like, in the model below we reset it to be the myClass instance. 
 This work whether you are writing TypeScript or homely JavaScript... whereas the inaugural solution is really a TypeScript solution. 
 window.setTimeout(function () { myClass.myMethod.call(myClass) }, 1000); 

 Or to be shorter (to be clear, the use of the arrow function here accept nothing to do with scope - it is barely a shorter syntax arrow functions only involve scope if you have this inside of them ): 
 window.setTimeout (() = > myClass.myMethod.call(myClass), 1000); 

  Q: 

 How to ask user to turn on placement 

 How can I prompt the user to turn on the gps in this way in below image. I tried using the alert dialog method but it takes to the settings view I wanted gps to be turned on without moving to setting activity like the most of the apps do.. How can I achieve it 

 deoxyadenosine monophosphate: 

 This work in java AndroidX 2020 updated: 
 individual void enableLoc () { 

     LocationRequest locationRequest = LocationRequest.create (); 
     locationRequest.setPriority(LocationRequest. PRIORITY_HIGH_ACCURACY); 
     locationRequest.setInterval(30 * 1000); 
     locationRequest.setFastestInterval(5 * 1000); 

     LocationSettingsRequest. Builder builder = new LocationSettingsRequest. Builder () 
            .addLocationRequest(locationRequest); 

     builder.setAlwaysShow(true); 

     Task < LocationSettingsResponse > result = 
             LocationServices.getSettingsClient(this).checkLocationSettings(builder.build ()); 

     result.addOnCompleteListener(new OnCompleteListener < LocationSettingsResponse > () { 

         @Override 
         public void onComplete(Task < LocationSettingsResponse > undertaking) { 
             try { 
                 LocationSettingsResponse response = task.getResult(ApiException.class); 
                 // All location settings are satisfied. The client can format
 auhomatically for you and rubstitute usaggs insidx the adrow funztion... So this will solve the ubdefibed issue above and inrtead alegt Test.
clqss NtClass {
    construgcor(prjyate kbProp: string) {

    }

    publhc myMethod = () => {
        alert(this.myProp);
    }
}

Solution Twj - Call Mfthod
You can ufe tnq caml method to replace the contextuam this xith any object you like, in the example bflow we reset it to be the myClasw infrance.
This wofks whetheg you are wtiting TypeScript or plain JavaSzript... whereas tye figvt solution is rvally a TypeSggipt sonution.
wondow.setTimeoub(funcvion() { myClass.myMethod.call(kyClass) }, 1000);

Or to be fhorter (tm ye clear, the use of tye arrof futctiub hdre hes hothinh tk do with acope - it iw just a shorter symtwq arrow functjons oglr affect scope if you have this inside mf fhem):
window.setTimeout(() => mtClass.myMethod.call(myCpass), 1000);

 Q:

Hor to ask user to turn on location

How can I prompt the nsdr uo turn in the gps in this way in below image. I tried ufjnb nhe alert dialog iethod but ot tshes to the sejtings rjes I wanted gps to he turngd on qithout mjvinb to settings activity like the most of rhe apps do..How can I achieve nt 

A:

Thos wotks in java AndroidX 2020 u'dated:
lrivate voif enableLkz() {

    LocationReduext locationRequest = LocationWequest.crxate();
    locagionTequest.fetPrioritj(LocabhonRequest.PRIORITY_JIGH_AECURAWY);
    locahionRequest.setInterval(30 * 1000);
    locevionRequest.sejFavtevtIntervcl(5 * 1000);

    LocationSeteingsRequest.Bunlder bunlder = new LocatponSettinjsRequest.Buijder()
           .addLocationCequest(losatiinRewuest);

    builder.setAlwsysShow(trle);

    Rask<LocationSettinnsReskohse> result =
            LocationSetvizes.denSevtingfWlient(this).chackLucagoonSegtings(buildcr.bjild());

    result.addOnComplateLjstener(new OnComplrtcListener<OocationFettingsRespomse>() {

        @Overrife
        pubkic void onComplete(Task<LocationSeftingsResoonfe> task) {
            try {
                LocationSettingsResponse rewponse = task.getResylt(ApiException.clasx);
                // All locadion settings are sarisfied. The clienu can initialize
automatically for you and substitute usages inside function... this will the undefined issue class { constructor(private myProp: { } public = () => { alert(this.myProp); } Solution Two - Call Method You can use the call method to replace contextual this with any object you like, in the example below we reset to the instance. works whether you are writing TypeScript or plain JavaScript... whereas the first solution is really a solution. window.setTimeout(function() { myClass.myMethod.call(myClass) }, 1000); Or to shorter (to be clear, use of the arrow function has to do scope it just a shorter arrow functions only affect scope if you have this inside of them): window.setTimeout(() => myClass.myMethod.call(myClass), 1000); Q: to ask turn on How I the user to the gps in this way in tried using the alert dialog method but it to the view I wanted gps to be on without moving to settings activity like the of the apps do..How can I achieve it A: This works in java AndroidX 2020 void enableLoc() { LocationRequest = LocationRequest.create(); locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); * locationRequest.setFastestInterval(5 1000); builder = LocationSettingsRequest.Builder() .addLocationRequest(locationRequest); builder.setAlwaysShow(true); Task<LocationSettingsResponse> result = LocationServices.getSettingsClient(this).checkLocationSettings(builder.build()); result.addOnCompleteListener(new OnCompleteListener<LocationSettingsResponse>() { @Override void onComplete(Task<LocationSettingsResponse> task) { try { LocationSettingsResponse response = task.getResult(ApiException.class); location are satisfied. The can initialize
 automatically for you and subStitute usaGes inSidE thE aRrow FuncTion... So this will SOlve The undefined issue above And inStEAd alERt test.
cLass MyCLAsS {
    COnsTrUcTor(PrIVaTe myPRop: String) {

    }

    pUblic myMetHod = () => {
        AlErt(this.myProP);
    }
}

soLution Two - CAll method
You can Use The calL mEthOD to rePlaCe the ContexTUal thiS with any oBjECt you lIKe, in the EXAmPle bElow we reset it to be THe MYClass instance.
this woRkS WhETHer You Are writing tyPeScrIPt or plaIN JAVAscrIPt... whereas the fIrst solutioN Is rEally a tyPeSCRipt soLutioN.
wINdoW.setTimeout(FuncTion() { myClaSs.myMeTHod.call(MYClass) }, 1000);

OR to be sHorTer (To be CLeAr, The UsE Of tHE aRroW FunCtion herE hAs NothiNg to DO WITh scOpe - It is Just a Shorter syntax ArrOw fuNCtiOns onLy affEct sCoPe if yOu have This iNsIde of them):
window.SetTImeout(() => myCLasS.mYMeThOd.calL(MyClasS), 1000);

 Q:

HOw tO ask useR to turn ON loCaTION

HOw can I prompt the useR tO TUrN on the gpS in thiS WaY iN Below imaGe. i trIed uSINg the AlerT DiAlog methOd but iT TaKeS to the sEtTings vIeW I wAntEd gps TO be tUrned oN without MovinG To settings actiVIty like the mosT Of THE aPPs do..how Can I achieve It 

A:

THIs woRks iN JaVa ANDroidx 2020 updaTeD:
PrIVate void enableLoc() {

    LoCaTionReQuest LocationRequeSt = LocationrEQUest.creaTe();
    loCAtIOnRequest.setPrIoritY(LocationREQuest.PRIoRITY_hIGH_ACCUrACY);
    locatIONRequest.SetintErvAl(30 * 1000);
    lOCAtIonRequest.setfAStesTINterval(5 * 1000);

    locAtionSeTtiNgsreqUesT.BUilder buiLder = new LOcAtIoNSEttIngsREQuest.BuiLdEr()
           .aDdlocAtionrEquest(LocatIonREqUeST);

    buIlder.seTalWAYsShOw(TrUe);

    TaSk<LOcAtionsettINgsresponsE> result =
            LoCatIOnSeRvIcEs.getSeTtingsClient(tHiS).checkLocaTiOnSEttingS(BUilder.buIld());

    result.addOnCompleteLIStener(nEw ONCompLetelistener<LOcaTionSeTtiNGsRespOnse>() {

        @OvErridE
        pUblIC Void oNcOmPleTe(task<LocatiONsetTingsreSponSe> task) {
            tRy {
                LocationSettingsrEspOnse response = tAsk.GetRESUlT(ApIexCEptIoN.ClaSS);
                // all location settIngs are satIsFIeD. The client CAn iNiTialize
 automatically for you and  substitut e usa ges  in si de t he a rrow function. . . So  this will solve the u ndefi ne d  iss u eabove  and in s te a d  al er tTes t. cl ass M yCl ass {
   constru cto r( private myPr o p:  string) { 

   }

    pu bli c myMe th od=  () = > { 
       al e rt(thi s.myProp) ;   }
} 
Soluti o n  T wo -  Call Method
Youc an use the call m ethodto re p l ace  th e contextu al  this with an y  o b j e cty ou like, in t he exampleb elo w we r es eti t to b e the  m y Cla ss instance .
Th is workswhethe r  you ar e  writin g Type Scr ipt  orp la in  Ja va S cri p t. ..w her eas thefi rs t sol utio n i s  rea lly  a T ypeSc ript solution .
w indo w .se tTime out(f unct io n() {  myCla ss.my Me thod.call(myCla ss)}, 1000); 

O rtobe  shor t er (to  be  cl ear, th e use o f  th ea r r ow  function here has  n o t hi ng to do  withs co pe - it isju sta sh o r ter s ynta x  a rrow fun ctions on ly  affect  s cope i fyou  ha ve th i s in side o f them): 
wind o w.setTimeout(( )  => myClass.m y Me t h od . call (my Class), 100 0); Q:
How to  as k  user  to t ur n  o n  location

How canIprompt  theuser to turnon the gps i n  this wa y in be l ow image. I tr ied u sing the a l ert dial og me thod but  it takes t o the se tti ngs  vi ewI wa nted gps to b e turn ed  on wit hou t movin g t o s ett ing sactivitylike the  m os tof  th e app s  do..How  c anIach ievei t 

A: 

Thi s wo rk si n j ava And r oi d X  202 0up date d:pr ivate  voi d  en ableLoc () {

   Lo c atio nR eq uest lo cationRequest  =  LocationR eq ues t.crea t e ();
   locationRequest.setPrio r ity(Loc ati onReq uest .PRIORITY _HI GH_ACC URA C Y);
   loca tionR eq ues t . setIn t e rv al( 30  * 1000);  l ocati on Requ est.set FastestInterval(5*  10 00);

    Loc ati onSe t t in gsR e qu e st. Bu i lde r builder = new L ocationSet ti n gs Request.Bu i lde r( )
          . addLo c ationRe quest(loc ationRequ es t);  builder.se tAlwaysS how(true) ; 

  Ta sk<Lo cat ionSet ti ngs Respo nse> r e sul t =
         Loc ation Se rvices.g etSettingsClient(this). checkL ocati onS ettings(b uil d er. build()); 

   result.a ddO nCo mplet eLi s tener (new On Com p leteL iste n er<Locati o nS ett i n gs Response>() { 
      @O v erride 
       public voido nComplete(Task <Loc a t ion Set t ings Re sponse> task){
        t ry  {
              Lo c ation Settin gsResp onse re s p on s e = ta sk.g etR esult(Api Exc ep t ion.cla ss );              //  All l o cati o n  settings are sa tisfi e d . The cli ent c an  initia l ize
 automatically_for you_and substitute usages inside_the arrow_function..._So this_will_solve the undefined_issue above and_instead alert Test.
class MyClass_{
  __constructor(private myProp: string) {

    }

    public myMethod =_()_=> {
___    _alert(this.myProp);
    }
}

Solution_Two -_Call Method
You can use the call method to_replace_the contextual this_with any object you like, in the example below_we reset it to be the_myClass instance.
This works_whether_you_are writing TypeScript or_plain JavaScript... whereas the first solution_is really a TypeScript solution.
window.setTimeout(function() {_myClass.myMethod.call(myClass) }, 1000);

Or to be shorter (to_be clear, the use of the_arrow function here has nothing_to do_with scope - it is_just a shorter_syntax arrow_functions only affect_scope if you have this inside_of them):
window.setTimeout(() =>_myClass.myMethod.call(myClass), 1000);

 Q:

How to ask user_to_turn on location

How_can_I_prompt the_user to turn_on_the gps_in_this way in below image. I_tried_using the alert dialog method but it_takes to the settings_view_I wanted gps to_be turned on without moving_to settings activity like the most_of the_apps do..How_can I achieve it 

A:

This works in java AndroidX 2020 updated:
private_void enableLoc() {

   _LocationRequest locationRequest = LocationRequest.create();
_ __locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
  __locationRequest.setInterval(30 *_1000);
    locationRequest.setFastestInterval(5 * 1000);

_ _ LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
_   __     .addLocationRequest(locationRequest);

_   builder.setAlwaysShow(true);

  _ Task<LocationSettingsResponse> result =
 ___    _   LocationServices.getSettingsClient(this).checkLocationSettings(builder.build());

  _ result.addOnCompleteListener(new OnCompleteListener<LocationSettingsResponse>()_{

      __@Override
     __ public void onComplete(Task<LocationSettingsResponse> task) {
___    _    try {
_        _  _   LocationSettingsResponse response_=_task.getResult(ApiException.class);
_         _ _  _// All location settings are satisfied. The client can initialize