Cannot resolve maketext() method of Toast

后端 未结 18 1279
南笙
南笙 2021-02-07 02:02

I am getting error while creating a Toast

Toast toast = Toast.makeText(this, text, duration);

I am getting cannot resolve ma

18条回答
  •  温柔的废话
    2021-02-07 02:42

    Grab the context from the calling activity (eg. this or MainActivity.this) and pass it into the method your Toast resides in. That way it lives together with the calling activity.

    Application context, which you get from getApplicationContext() and getContext() is mainly for long running processes. Using it for short lived processes can lead to memory leaks.

提交回复
热议问题