我试图在活动暂停之前通过使用以下代码覆盖onPause方法来显示toast消息:
@Override
protected void onPause() {
Toast.makeText(this, "Paused", Toast.LENGTH_LONG);
super.onPause();
}
根据此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."
但是根本不显示Toast消息。
答案 0 :(得分:9)
变化:
Toast.makeText(this, "Paused", Toast.LENGTH_LONG)
为:
Toast.makeText(this, "Paused", Toast.LENGTH_LONG).show()