你好,游客 登录 注册 搜索
背景:
阅读新闻

Android中Activity的切换

[日期:2011-07-31] 来源:Linux社区  作者:wangchenggong1988 [字体:大 中 小]
登陆成功后跳转的页面对应的Activity
  1. <span style="color:#666666;">public class SucActivity extends Activity implements OnClickListener{  
  2.       
  3.     private TextView textView;  
  4.       
  5.     private Button button ;  
  6.       
  7.     @Override  
  8.     protected void onCreate(Bundle savedInstanceState) {  
  9.         super.onCreate(savedInstanceState);  
  10.         //绑定布局文件   
  11.         setContentView(R.layout.suc);  
  12.           
  13.         textView = (TextView) findViewById(R.id.result);  
  14.         button = (Button) findViewById(R.id.examplebutton);  
  15.           
  16.         button.setOnClickListener(this);  
  17.         //获取AppActivity中传来的值   
  18.         </span><span style="font-size:32px;color:#999900;"><strong><em>咋放咋取</em></strong></span><span style="color:#666666;">  
  19.         Intent intent = getIntent(); </span><span style="color: rgb(51, 204, 0); ">如果采用的是intent直接装常规的数据类型</span><span style="color:#666666;">  
  20.         //Bundle b = intent.get<span style="color: rgb(255, 0, 0); ">Extras</span></span><span style="color:#666666;">();  </span><span style="color: rgb(51, 204, 0); ">先用bundle将数据封装成键值对的形式,在用intent装载 </span><span style="color: rgb(51, 204, 0); ">intent.put<span style="color:#ff0000;">Extras</span>(bundle);</span><span style="color:#666666;">   
  21.         User user = (User) intent.getSerializableExtra("user");</span><span style="color:#666666;"><span style="color: rgb(51, 204, 0); ">用intent装载实现可序列化接口的类</span>  
  22. </span>  
 
  1.                <span style="color:#666666;">String name = user.getName();//b.getString("name");//intent.getStringExtra("name");   
  2. String pwd = user.getPwd();//b.getString("pwd");//intent.getStringExtra("pwd");   
  3.   
  4. textView.setText("欢迎你," + name);</span>  
  1. <span style="font-size:24px;color:#ff9900;background-color: rgb(51, 102, 255);"><strong>其实到这里,任务已经完成,但需要知道,Activity的切换不仅可以发生在同一个应用程序中,还可以发生在不同的应用程序之间</strong></span>  
  1. <span style="color:#666666;">  
  2.   
  3. <span style="white-space:pre">    </span>  
  4. <span style="white-space:pre">    </span>@Override  
  5. <span style="white-space:pre">    </span>public void onClick(View v) {  
  6. <span style="white-space:pre">        </span>  
  7. <span style="white-space:pre">        </span>//</span><span style="font-size:24px;color:#ffcc00;"><strong>隐式意图</strong></span><span style="color:#666666;">   
  8. </span><span style="color: rgb(102, 102, 102); white-space: pre; ">     </span><span style="color:#666666;">  
  9. </span><span style="color: rgb(102, 102, 102); white-space: pre; ">     </span><span style="color:#666666;">//Uri uri = Uri.parse("tel://111000");   
  10. </span><span style="color: rgb(102, 102, 102); white-space: pre; ">     </span><span style="color:#666666;">Uri uri = Uri.parse("smsto:111000");  
  11. </span><span style="color: rgb(102, 102, 102); white-space: pre; ">     </span><span style="color:#666666;">  
  12. </span><span style="color: rgb(102, 102, 102); white-space: pre; ">     </span><span style="color:#666666;">Intent intent = new Intent(Intent.ACTION_SENDTO,uri);  
  13. </span><span style="color: rgb(102, 102, 102); white-space: pre; ">     </span><span style="color:#666666;">intent.putExtra("sms_body", "Hello,Android!This is a sms!");  
  14. </span><span style="color: rgb(102, 102, 102); white-space: pre; ">     </span><span style="color:#666666;">startActivity(intent);  
  15. </span><span style="color: rgb(102, 102, 102); white-space: pre; "> </span><span style="color:#666666;">}  
  16. </span><span style="color: rgb(102, 102, 102); white-space: pre; "> </span><span style="color:#666666;">  
  17. </span><span style="color: rgb(102, 102, 102); white-space: pre; "> </span><span style="color:#666666;">  
  18. </span>  

 

  1. <span style="color:#666666;">       
  •     }  
  • </span>  
  • linux
    相关资讯       Android教程 
    本文评论   查看全部评论 (0)
    表情: 表情 姓名: 字数

           

    评论声明
    • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
    • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
    • 本站管理人员有权保留或删除其管辖留言中的任意内容
    • 本站有权在网站内转载或引用您的评论
    • 参与本评论即表明您已经阅读并接受上述条款