在以下代码行中......
ProgressDialog progressDialog = ProgressDialog.show(getBaseContext(), "LOADING_TITLE", "LOADING_MESSAGE");
代替getBaseContext(),我试过......
getApplicationContext() // returns "java.lang.NullPointerException"
getBaseContext() // returns "java.lang.NullPointerException"
(NativeActivity)getApplicationContext()
this // returns "The method show(Context, CharSequence, CharSequence) in the Type ProgressDialog is not applicable for the arguments(new Runnable(){}, String, String)"
NativeActivity.this // returns "java.lang.NullPointerException"
NativeActivity.this.getApplicationContext() // returns "java.lang.NullPointerException"
NativeExtension.context.getActivity().getBaseContext() // returns “android.view.WindowManager$BadTokenException: Unable to add window — token null is not for an application”
myActivity.getApplicationContext() // returns “android.view.WindowManager$BadTokenException: Unable to add window — token null is not for an application”
myActivity.getBaseContext() // returns “android.view.WindowManager$BadTokenException: Unable to add window — token null is not for an application”
其中。我不确定为什么它不起作用。在扩展FREContext的NativeExtensionContext中,我使用getActivity()将活动传递给NativeActivity。一切正常但我得到一个“Nullpointerexception”或“android.view.WindowManager $ BadTokenException:无法添加窗口 - 令牌null不适用于应用程序”当我尝试获取对Context的引用时。
任何有使用Adobe AIR Native Extensions和/或Android Java经验的人都会很棒。
答案 0 :(得分:0)
NativeExtension.context.getActivity().getBaseContext() // this should work.
我唯一能想到的就是确保你在Activity中工作。也就是说,您从FREFunction实例初始化的Activity。
答案 1 :(得分:0)
将此添加到您的班级:
public static FREContext myANEContext=null;
....
....
ProgressDialog progressDialog = ProgressDialog.show(myANEContext.getActivity().getBaseContext(), "LOADING_TITLE", "LOADING_MESSAGE");
在使用您的课程之前,不要忘记传递FREFunction
的值:
public class MyANEfunction implements FREFunction{
@Override
public FREObject call(final FREContext context, FREObject[] args) {
try{
myANEClass.myANEContext=context;
....