我们可以通过在上下文中使用getWindow()获取每个Activity的Touch事件:
//set Window.Callback for getting touch event final Window window = context.getWindow(); final Window.Callback localCallback = window.getCallback(); window.setCallback(new MyWindowCallback(localCallback));
如何在不使用上下文的情况下实现它?
有没有办法删除这个回调(因为窗口类没有任何删除回调方法?
有一种方法可以获取Application上下文而不传递它.我在生产环境中使用过这段代码,这很好用.
private static Application getApplicationContext() throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { Context context; final Class> activityThreadClass = Class.forName("android.app.ActivityThread"); final Method method = activityThreadClass.getMethod("currentApplication"); context = (Application) method.invoke(null, (Object[]) null); Log.d(tag_, "Context is " + context); application = (Application)context; return application; }