子活动调用 finish() 后未调用 onActivityResult
尽管有几个关于这个主题的问题,但我找不到正确的答案。
我有一个主要活动(这是选项卡视图中的一个活动),我从其中调用登录活动。
Button chdbtn=(Button)findViewById(R.id.Add);
chdbtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent myIntent = new Intent(main.this, Login.class);
startActivityForResult(myIntent, 1001);
}
});
protected void onActivityResult(int requestCode, int resultCode, Intent data){
if(requestCode == 1001)
{
if(resultCode == RESULT_OK)
{
Log.i("Info","Inside");
}
}
}
在我的登录类中,当我单击按钮时,我正在执行此操作
Button chdbtn=(Button)findViewById(R.id.Addchild);
chdbtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent Ireturn = new Intent();
setResult(RESULT_OK,Ireturn);
finish();
}
});
但是当我单击登录活动中的按钮时,控件不会进入主活动的 onActivityResult 方法。谁能指导我这是什么问题。
VIJAYapp.sample.ChildEntry1$1/onClick:23
INFO/ActivityManager(59):启动活动:Intent { cmp=app.sample/.ChildLogin }
WARN/ActivityManager(59):从非活动上下文调用 startActivity;强制 Intent.FLAG_ACTIVITY_NEW_TASK 为: Intent { cmp=app.sample/.ChildLogin }
DEBUG/PhoneWindow(999):无法保存哪个视图具有焦点,因为焦点视图 com.android.internal.policy.impl.PhoneWindow$DecorView@ 43e4b620 没有 ID。
INFO/ActivityManager(59): 显示的活动 app.sample/.ChildLogin: 460 毫秒(总计 460 毫秒)
INFO/VIJAY(999): VIJAYapp.sample.ChildLogin$1/onClick:24
上面是我单击时收到的日志在按钮上。我可以看到活动存在一些问题..有什么答案吗?
Though there are several questions regarding this topic, I could not find a right answer to this.
I have a main activity (This is one activity in a tabview) from where I am calling the login activity.
Button chdbtn=(Button)findViewById(R.id.Add);
chdbtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent myIntent = new Intent(main.this, Login.class);
startActivityForResult(myIntent, 1001);
}
});
protected void onActivityResult(int requestCode, int resultCode, Intent data){
if(requestCode == 1001)
{
if(resultCode == RESULT_OK)
{
Log.i("Info","Inside");
}
}
}
And in my login class, When I click on a button, I am doing this
Button chdbtn=(Button)findViewById(R.id.Addchild);
chdbtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent Ireturn = new Intent();
setResult(RESULT_OK,Ireturn);
finish();
}
});
But when I click on the button in login activity, the control is not coming to the main activities onActivityResult method. Can anyone guide me what is the issue.
VIJAYapp.sample.ChildEntry1$1/onClick:23
INFO/ActivityManager(59): Starting activity: Intent { cmp=app.sample/.ChildLogin }
WARN/ActivityManager(59): startActivity called from non-Activity context; forcing Intent.FLAG_ACTIVITY_NEW_TASK for: Intent { cmp=app.sample/.ChildLogin }
DEBUG/PhoneWindow(999): couldn't save which view has focus because the focused view com.android.internal.policy.impl.PhoneWindow$DecorView@43e4b620 has no id.
INFO/ActivityManager(59): Displayed activity app.sample/.ChildLogin: 460 ms (total 460 ms)
INFO/VIJAY(999): VIJAYapp.sample.ChildLogin$1/onClick:24
Above is the log that I am getting when clicking on the buttons. I can see that there is some problem with the Activity..any answers?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想你的问题现在已经解决了。我对您的代码进行了一些修改,现在调用了 onActivityResult (检查修改后的代码: http: //www.4shared.com/file/_VR3zi28/CopySampleApptar.html?):
1.-当您调用登录活动类时,请使用: getParent().startActivityForResult(myIntent, 1001);
我对 Android 不是很熟练,但我知道控制活动之间的流程的是 ActivityGroup 类,因此您应该使用 ActivityGroup 实例启动活动。在上一行中,getParent() 引用了 ActivityGroup。
2.-因为您使用 ActivityGroup 实例,所以您的 onActivityResult 也必须放置在该类中。
I think your problem is solved now. I made some modifications to your code and the onActivityResult is now called (check the modified code: http://www.4shared.com/file/_VR3zi28/CopySampleApptar.html?):
1.-When you call the Login activity class use: getParent().startActivityForResult(myIntent, 1001);
I am not very skilled in Android but I understand that the one controlling the flow among activities is the ActivityGroup class, so you should start the activities using the ActivityGroup instance. In the previous line getParent() makes reference to the ActivityGroup.
2.-Because you use the ActivityGroup instance, your onActivityResult must be placed in that class as well.
getIntent()替换这些行,
考虑用
返回启动登录的活动。
Consider replacing the lines
with
getIntent() returns the Activity that started Login.