How can I start an Activity from a non-Activity class?
Once you have obtained the context in your onTap() you can also do:
Intent myIntent = new Intent(mContext, theNewActivity.class);
mContext.startActivity(myIntent);
Your onTap
override receives the MapView
from which you can obtain the Context
:
@Override
public boolean onTap(GeoPoint p, MapView mapView)
{
// ...
Intent intent = new Intent();
intent.setClass(mapView.getContext(), FullscreenView.class);
startActivity(intent);
// ...
}
I don't know if this is good practice or not, but casting a Context object to an Activity object compiles fine.
Try this: ((Activity) mContext).startActivity(...)
You can define a context
for your application say ExampleContext
which will hold the context of your application and then use it to instantiate an activity like this:
var intent = new Intent(Application.ApplicationContext, typeof(Activity2));
intent.AddFlags(ActivityFlags.NewTask);
Application.ApplicationContext.StartActivity(intent);
Please bear in mind that this code is written in C#
as I use MonoDroid, but I believe it is very similar to Java
. For how to create an ApplicationContext
look at this thread
This is how I made my Application Class
[Application]
public class Application : Android.App.Application, IApplication
{
public Application(IntPtr handle, JniHandleOwnership transfer) : base(handle, transfer)
{
}
public object MyObject { get; set; }
}