0

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.

lowerkey
  • 8,105
  • 17
  • 68
  • 102

2 Answers2

3

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.

Falmarri
  • 47,727
  • 41
  • 151
  • 191
  • I know I don't implement the lifecycle, but nonetheless, it is my understanding that for my application to fit in well with other applications, it has to respond to certain life cycle events, such as OnCreate, OnStart, OnPause, OnStop, OnDestroy, etc, see http://developer.android.com/guide/topics/fundamentals.html. Thanks for the advice on not going off on my own. I am trying to cobble together my application from tutorials on how to create a context menu, how to quit an application (they go hand in hand, imo). Next Step: getting current location data, ... – lowerkey Oct 14 '10 at 18:55
1
this.finish();

should work.

BlackDragonBE
  • 264
  • 1
  • 5
  • this.finish(); crashes my application. The phone responds with "The application Geo Message 4" (process us.gravebook.geomessage4) has stopped unexpectedly. Please try again." The reason I asked this question was to avoid that kind of thing. – lowerkey Oct 15 '10 at 03:10