其他類用在我Mainactivity的Android環境:比活動
LoginUser.loginUser(username.getText().toString(),password.getText().toString(), getApplication());
所以在我的LoginUser類, 我要開始這樣一個對話框:
new AlertDialog.Builder(context).set.....
但失敗了, 得到如下故障信息:
android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
另外我想使用像
Intent intent = new Intent(context, ABC.class)
context.startActivity(intent);
也失敗。並得到這樣的錯誤信息:
android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
我對所有這些都很困惑,任何人都可以幫助我嗎?非常感謝你!
請添加完整的代碼,你將如何展現dailog是指凡在活動或服務或片段? –