Cannot resolve maketext() method of Toast

后端 未结 18 2412
旧时难觅i
旧时难觅i 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:37

    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.

提交回复
热议问题