我有一个地图视图的活动,展示了一些 OverlayItems
。在覆盖的中的onTap
的方法,我想引发新的活动,显示了这个覆盖照片的全屏,例如。
I have a map view activity that shows a few OverlayItems
. In the onTap
method of an overlay, I want to trigger a new activity that shows this overlay photo as a fullscreen, for example.
当我这样做,在我的叠加类:
When I do this inside my overlay class:
Intent intent = new Intent();
intent.setClass(getApplicationContext, FullscreenView.class);
startActivity(intent);
..它找不到应用程序上下文,因为我不是一个活动的范围。
.. it can't find an application context, as I am not in the scope of an activity.
当我一个方法添加到我的主要活动,比方说 startFullscreen
:
When I add a method to my main activity, let's say startFullscreen
:
public static void startFullscreen() {
if (sCurrentPhoto != null) {
Intent intent = new Intent();
intent.setClass(getApplicationContext(), FullscreenView.class);
startActivity(intent);
}
}
我不能叫 getApplicationContext()
和 startActivity()
,因为我在一个静态的背景下。我需要静态方法但是调用它在覆盖类如 MainView.startFullscreen()
。
I can not call getApplicationContext()
and startActivity()
, because I am in a static context. I need the static method however to call it in the Overlay class like MainView.startFullscreen()
.
简而言之:我如何开始一个活动从非活动类
推荐答案
您中的onTap
覆盖接收图形页面
从你可以得到上下文
:
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);
// ...
}
相关推荐
最新文章