简体   繁体   English

如何在android中的onPause()之前显示toast消息?

[英]how to display toast message before onPause() in android?

I am attempting to display a toast message before the activity pauses by overriding onPause method with this code: 我试图通过使用以下代码覆盖onPause方法,在活动暂停之前显示一个Toast消息:

@Override
protected void onPause() {
    Toast.makeText(this, "Paused", Toast.LENGTH_LONG);
    super.onPause();
}

according to this http://developer.android.com/reference/android/app/Activity.html#ActivityLifecycle activity will not be paused until this method is returned: 根据此http://developer.android.com/reference/android/app/Activity.html#ActivityLifecycle活动在返回此方法之前不会暂停:

"Implementations of this method must be very quick because the next activity will not be resumed until this method returns."

However toast message is not displayed at all. 但是根本不显示Toast消息。

Change: Toast.makeText(this, "Paused", Toast.LENGTH_LONG) 更改: Toast.makeText(this, "Paused", Toast.LENGTH_LONG)

to: 至:

Toast.makeText(this, "Paused", Toast.LENGTH_LONG).show()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM