Android 用startforresult调用系统相册以后,不选照片 直接返回 在onacti
Android用startforresult调用系统相册以后,不选照片直接返回在onactivityresult函数里面接受的data为null而选择照片得话就可以dat...
Android 用startforresult调用系统相册以后,不选照片 直接返回 在onactivityresult函数里面接受的data为null 而选择照片得话就可以data就不为null 这是为什么 怎么解决啊?求大神指教
展开
展开全部
Test Activity
Java代码
package com.nico;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class Test extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btn1 = (Button) findViewById(R.id.btn1);
btn1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Test.this,Test01.class);
startActivity(intent);
}
});
}
}
Test 01 Activity
Java代码
package com.nico;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class Test01 extends Activity {
TextView txt2;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test01);
Button btn2 = (Button) findViewById(R.id.btn2);
txt2 = (TextView) findViewById(R.id.txt2);
btn2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setClass(Test01.this, Test02.class);
intent.putExtra("name", "nicolas");
//101 是请求码,方便在onActivityResult方法内处理不同请求码返回的intent 请求码须>=0
startActivityForResult(intent, 101);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.v("Test","------------------------->");
String ss = data.getStringExtra("newname");
txt2.setText(ss);
}
}
Test02 Activity
Java代码
Java代码
package com.nico;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class Test extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btn1 = (Button) findViewById(R.id.btn1);
btn1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Test.this,Test01.class);
startActivity(intent);
}
});
}
}
Test 01 Activity
Java代码
package com.nico;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class Test01 extends Activity {
TextView txt2;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test01);
Button btn2 = (Button) findViewById(R.id.btn2);
txt2 = (TextView) findViewById(R.id.txt2);
btn2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setClass(Test01.this, Test02.class);
intent.putExtra("name", "nicolas");
//101 是请求码,方便在onActivityResult方法内处理不同请求码返回的intent 请求码须>=0
startActivityForResult(intent, 101);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.v("Test","------------------------->");
String ss = data.getStringExtra("newname");
txt2.setText(ss);
}
}
Test02 Activity
Java代码
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询