Is it possible to start an activity from a regular java class?

Posted by Yotam on Stack Overflow See other posts from Stack Overflow or by Yotam
Published on 2013-10-28T15:45:25Z Indexed on 2013/10/28 15:53 UTC
Read the original article Hit count: 191

In my ActionBarSherlock I have the same menu items for all activities, so it seems unwise to define onClick handlers in each activity - they all do the same.

Instead I created a class called MyClickListener that implements com.actionbarsherlock.view.MenuItem.OnMenuItemClickListener, and in there I have a simple switch block that starts the appropriate activity.

Problem is that Intent constructor's first argument is of type Context, and even when I pass this to MyClickListener's constructor, I can't start any activity.

The same goes for every method that has a Context object as a parameter.

  1. Is there a way to work around it?
  2. What is a context object?

Thanks

© Stack Overflow or respective owner

Related posts about android

Related posts about android-activity