如何在家庭屏幕上展示吐司

发布于 2025-01-27 02:17:18 字数 305 浏览 2 评论 0原文

我有一项活动使用:

val i = Intent(Intent.ACTION_MAIN)
    i.addCategory(Intent.CATEGORY_HOME)
    startActivity(i)

Toast.makeText(this, "Fetching attendance, hold your phone close to the terminal ...", 
Toast.LENGTH_SHORT).show()

一旦调用了上述功能,就可以自动返回主屏幕,但是吐司不会显示。如何在主屏幕上表现出烤面包?

I have an activity that uses:

val i = Intent(Intent.ACTION_MAIN)
    i.addCategory(Intent.CATEGORY_HOME)
    startActivity(i)

Toast.makeText(this, "Fetching attendance, hold your phone close to the terminal ...", 
Toast.LENGTH_SHORT).show()

To automatically return to the home screen once the function above is called, but the toast does not show up. How can I make a toast show up while on the home screen?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

并安 2025-02-03 02:17:18

代表上下文。因此,而不是使用使用ApplicationContext

Toast.makeText(applicationContext, "Fetching attendance, hold your phone close to the terminal ...", 
Toast.LENGTH_SHORT).show()

The this stands for the context. So instead of using this use applicationContext

Toast.makeText(applicationContext, "Fetching attendance, hold your phone close to the terminal ...", 
Toast.LENGTH_SHORT).show()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文