About the Toast command [duplicate]












-2















This question already has an answer here:




  • what is the activity name in anonymous class

    4 answers




I want to know what 'this' means in the below Toast command:



Toast.makeText(MainActivity.this, "msg" ,Toast.Length_long ).show();


If possible could you please explain the whole command.










share|improve this question















marked as duplicate by Sergey Glotov android
Users with the  android badge can single-handedly close android questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 20 at 11:00


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • Just read: developer.android.com/guide/topics/ui/notifiers/toasts#java . If you do not know what a context is then you need to read some books/tutorials about it first.
    – ZUNJAE
    Nov 20 at 10:02










  • Toast is an object, not a command. You lack the fundamentals of OOP.
    – Fantômas
    Nov 20 at 10:21
















-2















This question already has an answer here:




  • what is the activity name in anonymous class

    4 answers




I want to know what 'this' means in the below Toast command:



Toast.makeText(MainActivity.this, "msg" ,Toast.Length_long ).show();


If possible could you please explain the whole command.










share|improve this question















marked as duplicate by Sergey Glotov android
Users with the  android badge can single-handedly close android questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 20 at 11:00


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • Just read: developer.android.com/guide/topics/ui/notifiers/toasts#java . If you do not know what a context is then you need to read some books/tutorials about it first.
    – ZUNJAE
    Nov 20 at 10:02










  • Toast is an object, not a command. You lack the fundamentals of OOP.
    – Fantômas
    Nov 20 at 10:21














-2












-2








-2








This question already has an answer here:




  • what is the activity name in anonymous class

    4 answers




I want to know what 'this' means in the below Toast command:



Toast.makeText(MainActivity.this, "msg" ,Toast.Length_long ).show();


If possible could you please explain the whole command.










share|improve this question
















This question already has an answer here:




  • what is the activity name in anonymous class

    4 answers




I want to know what 'this' means in the below Toast command:



Toast.makeText(MainActivity.this, "msg" ,Toast.Length_long ).show();


If possible could you please explain the whole command.





This question already has an answer here:




  • what is the activity name in anonymous class

    4 answers








java android






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 at 10:57









Sergey Glotov

16.6k117288




16.6k117288










asked Nov 20 at 9:53









Aravind D

12




12




marked as duplicate by Sergey Glotov android
Users with the  android badge can single-handedly close android questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 20 at 11:00


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by Sergey Glotov android
Users with the  android badge can single-handedly close android questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 20 at 11:00


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • Just read: developer.android.com/guide/topics/ui/notifiers/toasts#java . If you do not know what a context is then you need to read some books/tutorials about it first.
    – ZUNJAE
    Nov 20 at 10:02










  • Toast is an object, not a command. You lack the fundamentals of OOP.
    – Fantômas
    Nov 20 at 10:21


















  • Just read: developer.android.com/guide/topics/ui/notifiers/toasts#java . If you do not know what a context is then you need to read some books/tutorials about it first.
    – ZUNJAE
    Nov 20 at 10:02










  • Toast is an object, not a command. You lack the fundamentals of OOP.
    – Fantômas
    Nov 20 at 10:21
















Just read: developer.android.com/guide/topics/ui/notifiers/toasts#java . If you do not know what a context is then you need to read some books/tutorials about it first.
– ZUNJAE
Nov 20 at 10:02




Just read: developer.android.com/guide/topics/ui/notifiers/toasts#java . If you do not know what a context is then you need to read some books/tutorials about it first.
– ZUNJAE
Nov 20 at 10:02












Toast is an object, not a command. You lack the fundamentals of OOP.
– Fantômas
Nov 20 at 10:21




Toast is an object, not a command. You lack the fundamentals of OOP.
– Fantômas
Nov 20 at 10:21












3 Answers
3






active

oldest

votes


















1














In general when you use construct SomeClass.this that means that you are referring to the specific (frequently 'outer' class). In example you can have a code like:



class Apple { 

void outherMethod() {
}

class AppleType {

void innerMethod(){}
void method(){
Apple.this.outerMethod();
this.innerMethod();
}
}
}


Additionally, in this specific case on Android it means that you are using the activity's Context which is provided via MainActivity class.



So the whole command should be read as:




  • Create Toast widget inside context provided by MainActivity

  • It should display some text: "msg"

  • It should be visible for specific time defined by the constant: Toast.Length_long

  • finally, via show() method display it on device.






share|improve this answer





























    0














    'this' means itself.



    Toast.makeText(MainActivity.this, "msg" ,Toast.Length_long ).show();


    Call the toast method, and the required parameters are 'context', 'toast message' and 'toast duration'.



    Finally .show() means make toast to show.






    share|improve this answer





















    • whether "this" means that the mainactivity is contained within itself
      – Aravind D
      Nov 20 at 10:11










    • @AravindD MainActivity.this means MainActivity instance itself. So, the mainactivity.this gets context of activity(in this case - mainactivity)
      – eltoryn7
      Nov 20 at 10:28



















    0














    its clear and you can use it like this



    Toast toast =Toast.makeText(this, "msg", duration);
    toast.show();


    this: context

    "msg": your message

    duration: Toast.LENGTH_SHORT or Toast.LENGTH_LONG

    and you can change position by setting gravity



    toast.setGravity(Gravity.CENTER_VERTICAL|Gravity.CENTER_HORIZONTAL, 0, 0);


    this will show toast center screen






    share|improve this answer




























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














      In general when you use construct SomeClass.this that means that you are referring to the specific (frequently 'outer' class). In example you can have a code like:



      class Apple { 

      void outherMethod() {
      }

      class AppleType {

      void innerMethod(){}
      void method(){
      Apple.this.outerMethod();
      this.innerMethod();
      }
      }
      }


      Additionally, in this specific case on Android it means that you are using the activity's Context which is provided via MainActivity class.



      So the whole command should be read as:




      • Create Toast widget inside context provided by MainActivity

      • It should display some text: "msg"

      • It should be visible for specific time defined by the constant: Toast.Length_long

      • finally, via show() method display it on device.






      share|improve this answer


























        1














        In general when you use construct SomeClass.this that means that you are referring to the specific (frequently 'outer' class). In example you can have a code like:



        class Apple { 

        void outherMethod() {
        }

        class AppleType {

        void innerMethod(){}
        void method(){
        Apple.this.outerMethod();
        this.innerMethod();
        }
        }
        }


        Additionally, in this specific case on Android it means that you are using the activity's Context which is provided via MainActivity class.



        So the whole command should be read as:




        • Create Toast widget inside context provided by MainActivity

        • It should display some text: "msg"

        • It should be visible for specific time defined by the constant: Toast.Length_long

        • finally, via show() method display it on device.






        share|improve this answer
























          1












          1








          1






          In general when you use construct SomeClass.this that means that you are referring to the specific (frequently 'outer' class). In example you can have a code like:



          class Apple { 

          void outherMethod() {
          }

          class AppleType {

          void innerMethod(){}
          void method(){
          Apple.this.outerMethod();
          this.innerMethod();
          }
          }
          }


          Additionally, in this specific case on Android it means that you are using the activity's Context which is provided via MainActivity class.



          So the whole command should be read as:




          • Create Toast widget inside context provided by MainActivity

          • It should display some text: "msg"

          • It should be visible for specific time defined by the constant: Toast.Length_long

          • finally, via show() method display it on device.






          share|improve this answer












          In general when you use construct SomeClass.this that means that you are referring to the specific (frequently 'outer' class). In example you can have a code like:



          class Apple { 

          void outherMethod() {
          }

          class AppleType {

          void innerMethod(){}
          void method(){
          Apple.this.outerMethod();
          this.innerMethod();
          }
          }
          }


          Additionally, in this specific case on Android it means that you are using the activity's Context which is provided via MainActivity class.



          So the whole command should be read as:




          • Create Toast widget inside context provided by MainActivity

          • It should display some text: "msg"

          • It should be visible for specific time defined by the constant: Toast.Length_long

          • finally, via show() method display it on device.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 20 at 10:13









          rsulkowski

          263




          263

























              0














              'this' means itself.



              Toast.makeText(MainActivity.this, "msg" ,Toast.Length_long ).show();


              Call the toast method, and the required parameters are 'context', 'toast message' and 'toast duration'.



              Finally .show() means make toast to show.






              share|improve this answer





















              • whether "this" means that the mainactivity is contained within itself
                – Aravind D
                Nov 20 at 10:11










              • @AravindD MainActivity.this means MainActivity instance itself. So, the mainactivity.this gets context of activity(in this case - mainactivity)
                – eltoryn7
                Nov 20 at 10:28
















              0














              'this' means itself.



              Toast.makeText(MainActivity.this, "msg" ,Toast.Length_long ).show();


              Call the toast method, and the required parameters are 'context', 'toast message' and 'toast duration'.



              Finally .show() means make toast to show.






              share|improve this answer





















              • whether "this" means that the mainactivity is contained within itself
                – Aravind D
                Nov 20 at 10:11










              • @AravindD MainActivity.this means MainActivity instance itself. So, the mainactivity.this gets context of activity(in this case - mainactivity)
                – eltoryn7
                Nov 20 at 10:28














              0












              0








              0






              'this' means itself.



              Toast.makeText(MainActivity.this, "msg" ,Toast.Length_long ).show();


              Call the toast method, and the required parameters are 'context', 'toast message' and 'toast duration'.



              Finally .show() means make toast to show.






              share|improve this answer












              'this' means itself.



              Toast.makeText(MainActivity.this, "msg" ,Toast.Length_long ).show();


              Call the toast method, and the required parameters are 'context', 'toast message' and 'toast duration'.



              Finally .show() means make toast to show.







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Nov 20 at 10:05









              eltoryn7

              686




              686












              • whether "this" means that the mainactivity is contained within itself
                – Aravind D
                Nov 20 at 10:11










              • @AravindD MainActivity.this means MainActivity instance itself. So, the mainactivity.this gets context of activity(in this case - mainactivity)
                – eltoryn7
                Nov 20 at 10:28


















              • whether "this" means that the mainactivity is contained within itself
                – Aravind D
                Nov 20 at 10:11










              • @AravindD MainActivity.this means MainActivity instance itself. So, the mainactivity.this gets context of activity(in this case - mainactivity)
                – eltoryn7
                Nov 20 at 10:28
















              whether "this" means that the mainactivity is contained within itself
              – Aravind D
              Nov 20 at 10:11




              whether "this" means that the mainactivity is contained within itself
              – Aravind D
              Nov 20 at 10:11












              @AravindD MainActivity.this means MainActivity instance itself. So, the mainactivity.this gets context of activity(in this case - mainactivity)
              – eltoryn7
              Nov 20 at 10:28




              @AravindD MainActivity.this means MainActivity instance itself. So, the mainactivity.this gets context of activity(in this case - mainactivity)
              – eltoryn7
              Nov 20 at 10:28











              0














              its clear and you can use it like this



              Toast toast =Toast.makeText(this, "msg", duration);
              toast.show();


              this: context

              "msg": your message

              duration: Toast.LENGTH_SHORT or Toast.LENGTH_LONG

              and you can change position by setting gravity



              toast.setGravity(Gravity.CENTER_VERTICAL|Gravity.CENTER_HORIZONTAL, 0, 0);


              this will show toast center screen






              share|improve this answer


























                0














                its clear and you can use it like this



                Toast toast =Toast.makeText(this, "msg", duration);
                toast.show();


                this: context

                "msg": your message

                duration: Toast.LENGTH_SHORT or Toast.LENGTH_LONG

                and you can change position by setting gravity



                toast.setGravity(Gravity.CENTER_VERTICAL|Gravity.CENTER_HORIZONTAL, 0, 0);


                this will show toast center screen






                share|improve this answer
























                  0












                  0








                  0






                  its clear and you can use it like this



                  Toast toast =Toast.makeText(this, "msg", duration);
                  toast.show();


                  this: context

                  "msg": your message

                  duration: Toast.LENGTH_SHORT or Toast.LENGTH_LONG

                  and you can change position by setting gravity



                  toast.setGravity(Gravity.CENTER_VERTICAL|Gravity.CENTER_HORIZONTAL, 0, 0);


                  this will show toast center screen






                  share|improve this answer












                  its clear and you can use it like this



                  Toast toast =Toast.makeText(this, "msg", duration);
                  toast.show();


                  this: context

                  "msg": your message

                  duration: Toast.LENGTH_SHORT or Toast.LENGTH_LONG

                  and you can change position by setting gravity



                  toast.setGravity(Gravity.CENTER_VERTICAL|Gravity.CENTER_HORIZONTAL, 0, 0);


                  this will show toast center screen







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 20 at 10:26









                  New Developer

                  762




                  762















                      Popular posts from this blog

                      Create new schema in PostgreSQL using DBeaver

                      Deepest pit of an array with Javascript: test on Codility

                      Fotorealismo