我尝试开发Android应用程序,当在主要活动中点击主页按钮3次时,启动另一个活动。但这不适合我。
这是我的代码
HomeWatcher mHomeWatcher = new HomeWatcher(this);
mHomeWatcher.setOnHomePressedListener(new OnHomePressedListener() {
@Override
public void onHomePressed() {
T++; // to track the clicks
if (T==3){
Toast.makeText(getBaseContext(), "Home button pressed", Toast.LENGTH_LONG).show(); }
startActivity( new Intent (getBaseContext(),Main2Activity.class));}
// do something here...
}
});
mHomeWatcher.startWatch();
}
@Override
public void onStop() {
//Toast.makeText(this, "onstop",Toast.LENGTH_LONG).show();
if ( T==3 ){
startActivity( new Intent (getBaseContext(),Main2Activity.class));}
super.onStop();
}