我希望能够通过按下实体按钮 (home、back、menu 等) 来启动我的服务。如果用户长按其中一个按钮,服务应该调用一个方法。我该如何为我的情况实现广播接收器或监听器呢?
我希望能够通过按下实体按钮 (home、back、menu 等) 来启动我的服务。如果用户长按其中一个按钮,服务应该调用一个方法。我该如何为我的情况实现广播接收器或监听器呢?
public class MyActivity extends Activity {
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.content_layout_id);
final Button button = (Button) findViewById(R.id.button_id);
button.setOnLongClickListener(new View.OnLongClickListener() {
public boolean onLongClick(View v) {
// Perform action on click
return true;
}
});
}
}