从Service中启动Acitivity时向Activity中传递参数

来源:互联网 发布:天庭淘宝城 编辑:程序博客网 时间:2024/06/05 20:49

在service中写的方法启动activity,让activity获取传递的值:

      service端的代码:

            Intent video_test_intent = new Intent("com.broncho.intent.action.VIDEO_TEST");           
            video_test_intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            video_test_intent.putExtra("run_time", 5);
            video_test_intent.putExtra("break_time", 10);
            startActivity(video_test_intent);

 

     被启动的Activity端获取传递过来的参数代码:

        public void onCreate(Bundle savedInstanceState){
         super.onCreate(savedInstanceState);

 

         .......


        Log.w("TAG", "run_time = " + this.getIntent().getExtras().get("run_time"));    //=5
        Log.w("TAG", "break time = " + this.getIntent().getExtras().get("break_time"));   //=10    
    }

 

 2011-01-07

 

原创粉丝点击