开发者

Quitting an android application

I get that the android application is supposed to follow the Activity lifecycle, and I'm sure I'll get to fully implementing it. For starters though, I'm just trying to close the application when the user selects quit from an options menu, without crashing. Can someone help me out? I have a

public boolean onOptionsItemSelected(MenuItem item){
    switch(item.getItemId()){
    case R.id.quit:
        quit();
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

Right now R.id is underlined red, saying R.id cannot be resolved, event though i import us.gravebook.geomessage.R.开发者_StackOverflow社区


event though i import us.gravebook.geomessage.R

Do NOT do that. That's not how resources work. If you import R, your code WILL NOT WORK. If us.gravebook.gemoessage isn't the same package that your activity is in, it has even less of a chance of working (less than 0). You can just use R.id.whatever without importing R.

Secondly,
and I'm sure I'll get to fully implementing it

I don't think you understand what a lifecycle is. You don't implement anything. You (essentially) HAVE To follow the android lifecycle because that's how the framework works. Yeah you can bypass some stuff by killinlg processes and such, but that's a different story.

Do NOT just go off on your own and expect to be able to get anywhere. Follow the tutorials, follow the guides, work with the framework. Don't fight it unless you're SURE you know what you're doing.


this.finish();

should work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜