作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 android 新手,并尝试使用 AsyncTask
从服务器获取到 mysql 的连接
protected void onPostExecute(String result) {
if(result.equalsIgnoreCase("true"))
{
Intent intent = new Intent(context,profile.class);
//not usefull
//intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
((Activity)context).finish();
Toast.makeText(context, "done", Toast.LENGTH_LONG).show();
}else //..... the rest of the code .....//
}
一切正常,但当结果为真时,它并不打算进行新 Activity
并使用 ((Activity)context).finish();
它将崩溃
应用程序始终提示已完成
context
已定义 Context context
,我通过输入 this
从 MainActivity
获取其值
最佳答案
使用this
是对 Activity 的引用,我认为您应该引用应用程序上下文
来启动 Activity 。
if(result.equalsIgnoreCase("true"))
{
Intent intent = new Intent(context.getApplicationContext(),profile.class);
context.getApplicationContext().startActivity(intent);
((YourActivityName)context).finish();
Toast.makeText(context, "done", Toast.LENGTH_LONG).show();
}else //..... the rest of the code .....//
关于java - android studio AsyncTask 无意且 context.finish 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61469903/
我不知道这是否是其他人遇到的问题,但我在 python 中有这样的代码: def makemove(board,move,val): new=board new[move[0]][mo
不是重复的 我想在不使用任何默认电子邮件应用程序的情况下发送电子邮件,所以我进行了一些搜索,然后偶然发现了这个使用 JavaMail API 的解决方案 - Sending Email in Andr
在网络浏览器中,我希望能够使用 java 脚本打开任何已安装的应用程序(例如 facebook、twitter 等)。我无法更新 Intent 文件,只想从 java 脚本中进行更新。有没有办法从 j
我是一名优秀的程序员,十分优秀!