我的要求是一个活动正在调用另一个活动。当我从父活动的销售路线列表中单击单选按钮时,对话框(称为子)将会出现。它包含表单。完成小型工作后,它会转到以前的位置(需要继续工作)。
我这样做了:
Androidmanifest.xml
<activity android:theme="@android:style/Theme.Light.Panel" android:name=".SalesRouteDevitionActivity"
android:label="Sales Route Diviation">
</activity>
然后我的销售路线java部分列表是:
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
Object o = this.getListAdapter().getItem(position);
keyword = o.toString();
positions = position;
if(position != 0 ){
Bundle bundle = new Bundle();
Intent showContent = new Intent(v.getContext(),SalesRouteDevitionActivity.class);
int postion = position;
String aString = Integer.toString(postion);
bundle.putString("positon", aString);
showContent.putExtras(bundle);
startActivityForResult(showContent, 2);
}else{
Intent intent = new Intent(SalesRouteActivity.this, ListRetailerActivity.class);
Bundle bundle = new Bundle();
bundle.putString("RouteName", keyword);
intent.putExtras(bundle);
View view = SalesActivityGroup.group.getLocalActivityManager().startActivity("", intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView();
SalesActivityGroup.group.replaceView(view);
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if( resultCode==Activity.RESULT_OK){
Toast.makeText(this, "Reason has been successfully.", Toast.LENGTH_LONG).show();
if(resultCode==RESULT_OK)
Toast.makeText(this, "Reason has been successfully.", Toast.LENGTH_LONG).show();
else
Toast.makeText(this, "Fail", Toast.LENGTH_LONG).show();
}
// super.onActivityResult(requestCode, resultCode, data);
}
我的孩子活动是:
public class SalesRouteDevitionActivity extends Activity {
private String array_spinner[];
String param1 = "";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.route_diviation_popup);
array_spinner=new String[2];
array_spinner[0]="Rain";
array_spinner[1]="Floods";
Spinner s = (Spinner) findViewById(R.id.spinner1);
ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_spinner_dropdown_item, array_spinner);
s.setAdapter(adapter);
Button button = (Button) findViewById(R.id.submit);
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent intent= new Intent(getApplicationContext(),SalesRouteActivity.class);
Log.i("*********" ," --- " +getParent());
if (getParent() == null) {
setResult(RESULT_OK, intent);
} else {
getParent().setResult(RESULT_OK, intent);
}
finish();
}
});
}
完成弹出式活动后,我的问题是,它没有转到onActivityResult()
方法
我怀疑,如果主题为@android:style/Theme.Dialog
,那么我们可以使用onActivityResult()
;
请帮帮我......
我花了一天多......可能是小问题......
提前致谢....
答案 0 :(得分:0)
您没有从intent传递任何值,因此请尝试删除intent并使用如下:
的setResult(RESULT_OK);
答案 1 :(得分:0)
试试这段代码..
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent intent= SalesRouteDevitionActivity.this.getIntent();
Log.i("*********" ," --- " +getParent());
if (getParent() == null) {
SalesRouteDevitionActivity.this.setResult(SalesRouteDevitionActivity.RESULT_OK, intent);
} else {
SalesRouteDevitionActivity.this.getParent().setResult(SalesRouteDevitionActivity.RESULT_OK, intent);
}
finish();
}
});
答案 2 :(得分:0)
getParent().setResult(RESULT_OK, intent);
此行为might be
faluty,因为getParent()
返回调用活动,实际上如果从另一个活动X调用SalesRouteDevitionActivity
则返回THAT X活动。但由于该活动在OnPause()
并且正在侦听结果,因此您无法同时从同一X活动设置结果,而是从SalesRouteDevitionActivity设置结果,然后完成它。像
SalesRouteDevitionActivity.this.setResult(RESULT_OK, SalesRouteDevitionActivity.this.getIntent());
SalesRouteDevitionActivity.this.finish();
还要重写onActvityResult()
,然后测试请求代码,然后测试结果代码......
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.i("TEST ON RESULT", "SUCCESS");
if( requestCode==2){
if(resultCode==RESULT_OK)
Toast.makeText(this, "Reason has been successfully.", Toast.LENGTH_LONG).show();
else
Toast.makeText(this, "Fail", Toast.LENGTH_LONG).show();
}
答案 3 :(得分:0)
我已通过此链接完成此操作。
startActivityForResult from ActivityGroup? 。它对ActivityGroup的startActivityForResult非常有帮助
答案 4 :(得分:0)
我遇到了类似的问题。我有一个ActivityGroup管理子活动。其中一个子活动称为类似的外部意图(我的应用程序外部)。它从未在启动它的子活动中调用onActivityResult。
我终于弄清楚/记得这个问题是因为Android只允许嵌套的子活动层......即子活动不能嵌套子活动。要解决这个问题:
call getParent().startActivityForResult() from your sub-activity
your parent (the activitygroup) will be able to handle the onActivityResult. So I created a subclass of ActivityGroup and handled this onActivityResult.
You can re-route that result back to the sub-activity if you need to. Just get the current activity by getLocalActivityManager().getCurrentActivity() . My sub-activities inherit from a custom activity so I added a handleActivityResult(requestCode, resultCode, data) in that subclass for the ActivityGroup to call.