Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AndroidRuntimeException "Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag"

I create multiple layouts inside a listview, but when i click i get a AndroidRuntimeException "Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?"

Im adding

Intent.FLAG_ACTIVITY_NEW_TASK

to my intent but i get the same message! =(

      @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;
        }
like image 492
Jorgesys Avatar asked Dec 20 '12 18:12

Jorgesys


1 Answers

Replace getApplicationContext() with this. Most likely, you should do that everywhere in your code that you have getApplicationContext() -- only use getApplicationContext() when you specifically need the Application object.

like image 81
CommonsWare Avatar answered Nov 11 '22 00:11

CommonsWare