为什么不能回调onActivityResult方法?
public class MainActivity extends Activity {private Button import_number,import_content,pause,startsend;
private TextView number_content,smscontent;
Intent intent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
import_number=(Button)findViewById(R.id.button1);
pause=(Button)findViewById(R.id.button3);
startsend=(Button)findViewById(R.id.button4);
number_content=(TextView)findViewById(R.id.editText1);
smscontent=(TextView)findViewById(R.id.editText2);
import_number.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
MainActivity.this.getFile();
//number_content.setText(pathString);
}
});
}
//获取文件的路径
//返回包含文件路径的字符串
public void getFile(){
intent = new Intent();
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.setType("text/plain");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivityForResult(intent, RESULT_OK);
}
//回调设置文本框结果文件
protected void onActivityResult(int requestCode, int resultCode, Intent data){
Toast.makeText(getApplicationContext(), "ggg",Toast.LENGTH_LONG).show();
if(resultCode==Activity.RESULT_OK){
{
Uri uri = data.getData();
Cursor cursor = this.getContentResolver().query(uri, null, null, null, null);
cursor.moveToFirst();
/*
for (int i = 0; i < cursor.getColumnCount(); i++)
{// 取得图片uri的列名和此列的详细信息
System.out.println(i + "-" + cursor.getColumnName(i) + "-" + cursor.getString(i));
} */
number_content.setText(cursor.getColumnName(0));
}
}
} --------------------编程问答-------------------- intent = new Intent();
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.setType("text/plain");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivityForResult(intent, RESULT_OK);
这个打开了一个Activity,但未必执行了finish. --------------------编程问答-------------------- 你要跳转的Activity是不是设置成了单实例模式了? --------------------编程问答--------------------
我这个调用的系统的文件浏览器 我不知道哇 小白我不太清楚 --------------------编程问答-------------------- startActivityForResult(intent, RESULT_OK);
我把 RESULT_OK 改成数字就可以回调了是了
补充:移动开发 , Android