码迷,mamicode.com
首页 > 移动开发 > 详细

Android源码之简单定时器

时间:2014-10-01 21:26:31      阅读:197      评论:0      收藏:0      [点我收藏+]

标签:android   color   io   os   ar   java   sp   div   art   

public class MainActivity extends Activity implements OnClickListener {
 
    private Button bt_main_start;
    private Button bt_main_over;
    private EditText et_main_inputTime;
    private Intent mService;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mService = new Intent(this, MyService.class);
        initView();
    }
 
    private void initView() {
        bt_main_start = (Button) findViewById(R.id.bt_main_start);
        bt_main_over = (Button) findViewById(R.id.bt_main_over);
        et_main_inputTime = (EditText) findViewById(R.id.et_main_inputTime);
         
        bt_main_start.setOnClickListener(this);
        bt_main_over.setOnClickListener(this);
    }
 
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
 
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
        case R.id.bt_main_start:
            String minute = et_main_inputTime.getText().toString().trim();
            if(TextUtils.isEmpty(minute)){
                return;
            }
            mService.putExtra("minute", Integer.parseInt(minute));
            startService(mService);
            break;
        case R.id.bt_main_over:
            stopService(mService);
            break;
 
        }
    }
}

Android源码之简单定时器

标签:android   color   io   os   ar   java   sp   div   art   

原文地址:http://www.cnblogs.com/yingxiong123/p/4003440.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!