I’m trying to display a Toast notification in verifyPasswordAndUnlock() in PasswordUnlockScreen.java whenever a user enters the wrong password. I wrote the following code, and built successfully.
Toast.makeText(getContext(), "Invalid password", Toast.LENGTH_LONG).show();
However, the Toast doesn’t appear, because it actually appears in the home screen, which is invisible when the lock screen is on top. I verified this by having another Toast appear when the user successfully logs in, and that Toast only appears in the home screen after the Lock screen disappears
I suspect this is because getContext() returns the home screen’s context. How do I get the Lockscreen’s context? PasswordUnlockScreen.this doesn’t even compile, and mContext and context both have the same problem as getContext()
As has been said already, the problem is probably not with the Context. I guess you are working with the actual PasswordUnlockScreen source, and not subclassing it? If so, you could try using its
KeyguardStatusViewManagerto display your text: