如何停止按钮处理程序 - Android
当我调用按钮处理程序时,即使处理程序没有完成,应用程序也会在后台继续运行,我如何才能停止这种行为,并回退到线性执行?
qrscan.setOnClickListener( new View.OnClickListener() { //the Button listener
public void onClick(View view) { //the handler
if(initiateScan(activity) == null) //first thing i expect it to execute
initiateSend(activity); //the next thing which should be executed AFTER
}
}
);
When I call a buttonHandler, the app just continues in the background even though the Handler didn't finish, how can I stop this behaviour, and fall back to a linear execution?
qrscan.setOnClickListener( new View.OnClickListener() { //the Button listener
public void onClick(View view) { //the handler
if(initiateScan(activity) == null) //first thing i expect it to execute
initiateSend(activity); //the next thing which should be executed AFTER
}
}
);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您没有说太多 - 我们需要知道
initiateScan
和initiateSend
是如何工作的,但听起来initiateScan
正在使用startActivity
或startActivityForResult
去做这件事。如果是这样,您需要确保他们使用
startActivityForResult
,并将initiateSend
移动到onActivityResult< /code>
您的活动的方法。
活动是异步实体,您需要使用
onActivityResult
回调以您正在寻找的线性方式处理操作。有关详细信息,请阅读此处。
You aren't saying much - we'll need to know how
initiateScan
andinitiateSend
work, but it sounds likeinitiateScan
is usingstartActivity
orstartActivityForResult
to do it's thing.If so, you need to ensure they are using
startActivityForResult
, and moveinitiateSend
to theonActivityResult
method of your activity.Activities are asynchronous entities and you need to make use of the
onActivityResult
callback to handle actions in the linear manner you are looking for.For more info, read here.