欢迎来到天天文库
浏览记录
ID:51159599
大小:179.98 KB
页数:13页
时间:2020-03-19
《Android多个Activity之间跳转的归纳总结外文翻译.docx》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、多个Activity跳转的小结第一个例子:demo1 Main—>SecondActivity—>Main 从流程上看就是从Main跳转到SecondActivity,再从SecondActivity返回到Main。也就是将子Activity的数据返回给父Activity。 代码如下: Java代码 1.public class Main extends Activity { 2. 3. private Button btn; 4. private TextView request_text; 5. privat
2、e final int FIRST_REQUEST_CODE = 1; 6. 7. /** Called when the activity is first created. */ 8. @Override 9. public void onCreate(Bundle savedInstanceState) { 10. super.onCreate(savedInstanceState); 11. setContentView(R.layout.main); 12.
3、 13. request_text = (TextView)this.findViewById(R.id.request_text); 14. 15. btn = (Button)this.findViewById(R.id.btn); 16. btn.setOnClickListener(new OnClickListener() { 17. public void onClick(View v) { 18. Intent
4、i = new Intent(Main.this,SecondActivity.class); 19. i.putExtra("request_text_for_main", "从Main传递到SecondActivity"); 20. startActivityForResult(i, FIRST_REQUEST_CODE); 21. } 22. }); 23. } 24. 25. protected void onA
5、ctivityResult(int requestCode, int resultCode, Intent data) { 26. super.onActivityResult(requestCode, resultCode, data); 27. if(requestCode==FIRST_REQUEST_CODE && resultCode==Activity.RESULT_OK){ 28. if(data != null) { 1. request_tex
6、t.setText(data.getStringExtra("request")); 2. } 3. } 4. } 5.} Java代码 1.public class SecondActivity extends Activity{ 2. 3. private TextView request_text; 4. private Button btn; 5. private String text; 6. 7. public void onCre
7、ate(Bundle savedInstanceState) { 8. super.onCreate(savedInstanceState); 9. setContentView(R.layout.second); 10. 11. request_text = (TextView)this.findViewById(R.id.request_text); 12. 13. if (getIntent().getStringExtra("request_
8、text_for_main") != null) { 14. text = getIntent()
此文档下载收益归作者所有