- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我创建了一个登录 Activity ,它使用另一个类 - LoginService,它是一个用于网络通信的 AsyncTask。
public void onClick(View view) {
if (editTextPassword.getText().toString() != null & editTextUsername.getText().toString() != null){
new LoginService(editTextUsername.getText().toString(), editTextPassword.getText().toString()).execute();
if(loginSuccess!=false){
//Used to move to the Cases Activity
Intent casesActivity = new Intent(getApplicationContext(), CasesActivity.class);
startActivity(casesActivity);
}else{
Toast.makeText(getApplicationContext(),"Incorrect Details", Toast.LENGTH_LONG).show();
}
}
else{
//Display Toaster for error
Toast.makeText(getApplicationContext(),"Please enter your details", Toast.LENGTH_LONG).show();
}
}
在 LoginService 完成执行之前, Activity 已经通过 Intent 变量移动到另一个 Activity 。我不懂为什么。 LoginService 的想法是验证用户的凭据。如果它返回 true,那么它可以切换到另一个 Activity 。
最佳答案
您不希望以这种方式执行此操作。 .execute()
将尽快开始,但不能保证(并且可能保证不会)它会让您的loginSuccess
值(value)及时回馈给您。
new LoginService(...).execute();
之后的所有内容都应移至 onPostExecute()
中:
private Context mContext = null;
public void setContext(Context context) {
mContext = context;
}
@Override
protected void onPostExecute(Void result) {
if(loginSuccess!=false){
//Used to move to the Cases Activity
Intent casesActivity = new Intent(mContext, CasesActivity.class);
startActivity(casesActivity);
}else{
Toast.makeText(mContext,"Incorrect Details", Toast.LENGTH_LONG).show();
}
}
然后,您必须像这样调用 setContext()
:
LoginService service = new LoginService(editTextUsername.getText().toString(), editTextPassword.getText().toString());
service.setContext(getApplicationContext());
service.execute();
关于android - 如何将异步任务的结果返回到android中的 Activity ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14843850/
我最后一次使用C++是在它无法被管理之前。不过最近,我从 Java 回来,看到现在可以管理 C++ 了! 没过多久我就意识到gcnew 和^ 的用途。但是,我对容器有点卡住了。 如何创建一个容器,其元
我离开 Microsoft 堆栈已有一段时间了,专注于 Linux、开源内容和 PHP 中的 Web 开发。我曾经在 Dev Studio(所有 C 和 C++)中在 Windows 上进行一些桌面应
在我的程序中有两个 View Controller 。第一个有表格 View 。当我单击一个单元格时,相关的炎症会显示在第二个 View Controller 中。它运作良好。 当我返回到第一个 Vi
我使用 AVAssetWriter 和 CMSampleBuffer 数据(来自视频、音频输入)录制视频(.mp4 文件)。 在录制时我想处理帧,我正在将 CMSampleBuffer 转换为 CII
在 python 中有两种不同的离开循环的选项。 continue 将您带回到循环的开头,break 就像一个电灯开关,它会在脚本运行的剩余时间内切断循环。我的问题是我有一个 while True 循
我是 Git 的新手,我正试图恢复到 SourceTree 中的先前提交。我右键单击要还原到的提交,然后单击 checkout 。它给了我一个提示,说我的工作副本将成为一个独立的头。这是什么意思,这是
所以我决定在离开几年后,为了我的一些个人项目重新使用 Ruby on Rails。我想知道的是,找出 Rails 中的新功能的最佳资源是什么?自从 1.2 是新的以来,我什至没有真正接触过 Rails
我的项目有两个部分。第一部分是在 Storyboard中制作的,第二部分是 SKView。如何从 SKView 中的第二部分返回到主 UIView? 最佳答案 创建自定义 ViewController
所以我在大约四次提交前对我的项目做了一个糟糕的改变。我了解到我可以恢复到之前描述的状态 here ,并通过依次检查以前的提交(并在我的设备上测试它们),我已经确定了问题发生的位置。 现在我想回到坏改变
我想知道,在 Canvas 的 commandAction 方法中,如何让我的命令按钮回到 MIDlet 的开始? (基本上重新开始)。 当按键触发时,我将它带到一个新的列表页面。在该页面上,我有一个
我想知道是否可以使用 intro.js 返回到下一行。我尝试了\n 和其他类似的东西,但它们中的任何一个都有效并且不可能在文档中找到类似的东西。有谁知道这是否可能? 最佳答案 正确的做法是像这样使用
这是关于我发现我的应用程序面临的一个反复出现的问题,它与使用几个 DialogFragment 相关。我主要针对平台级别 8 设备,因此要使用 DialogFragments,我必须使用兼容性库。 每
我有一个 uiview 的问题,它放置在 Storyboard的一个位置,在应用程序启动后,我将 uiview 移动到第二个位置,并使用代码中的按钮进行动画处理。 int alpha = -212;
我有 Controller B,它使用委托(delegate)模式将数据发送回 Controller A,但由于某种原因我的 segue 没有触发。 是否有什么东西阻止我的 segue 被触发?我将如
我已经找到了处理除我需要的之外的所有内容的解决方案。这是场景 就像在 GMail 中一样 - 主要内容呈现在 iframe 中。单击主页上的链接会指向 iframe。这效果很好,而且无缝。此时,如果我
我有一个 RCP 程序,带有需要登录的启动屏幕。 我想制作一个注销按钮。通过单击此按钮,用户应该返回到初始屏幕,因此他必须重新登录.. 这可能吗? 提前致谢。 最佳答案 如果您使用org.eclips
我有一个数据框: df = pd.DataFrame({'Section': [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 6],
是否可以将元素 $("p") 返回到应用 mouseenter() 方法之前的确切颜色?或者我是否需要知道 mouseenter() 之前的颜色,然后使用 mouseleave() 应用该颜色?我希望
在 Matlab R2016b 中,显示某些数据类型的变量会显示有关该类型的信息。当通过不带最终分号键入变量来显示变量时会发生这种情况(使用 disp 函数时不会发生这种情况)。 比较例如: Matl
是否可以告诉 RSpec::Mocks 为一组值 stub 一个方法,否则回退到原始方法?例如: File.stub(:exist?).with(/txt/).and_return(true) Fil
我是一名优秀的程序员,十分优秀!