AndroidRuntimeException"从Activity上下文外部调用startActivity()需要FLAG_ACTIVITY_NEW_TASK标志"

Jor*_*sys 4 android runtime-error

我在listview中创建了多个布局,但是当我点击i得到一个AndroidRuntimeException时"从Activity上下文调用startActivity()需要FLAG_ACTIVITY_NEW_TASK标志.这真的是你想要的吗?"

我补充说

Intent.FLAG_ACTIVITY_NEW_TASK

我的意图,但我收到同样的消息!=(

      @Override
            public View getView(int position, View convertView, ViewGroup parent) {

                    retval=LayoutInflater.from(getApplicationContext()).inflate(R.layout.layout_anuncio, null);
                    ImageView image=(ImageView) retval.findViewById(R.id.imageAD);
                    LoadAds loadAds= new CargaAnuncios();
                    clickUrl = LoadAds.cargaImagenAnuncio(image, mContext, GlobalInfo.ANUNCIO_CARRIL_PORTADA);
                    image.setOnClickListener(new OnClickListener(){

                        @Override
                        public void onClick(View view) {
                            Bundle bundle=new Bundle();
                            bundle.putString("url", clickUrl);
                            Intent intent =new Intent(mContext,CustomWebView.class);
                            intent.putExtras(bundle);
                            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                            mContext.startActivity(intent);
                        }

                    });
            return retval;
        }
Run Code Online (Sandbox Code Playgroud)

Com*_*are 17

替换getApplicationContext()this.最有可能的是,您应该在代码中的任何地方执行此操作getApplicationContext()- 仅getApplicationContext()在您特别需要该Application对象时使用.


Jor*_*sys 0

我已经添加了:

父级.getApplicationContext()

而不仅仅是:

获取应用程序上下文()

整行是:

retval=LayoutInflater.from(parent.getApplicationContext()).inflate(R.layout.layout_anuncio, null);
Run Code Online (Sandbox Code Playgroud)