Rajubhai Rathod Rajubhai Rathod - 5 months ago 30
Android Question

Start activity after finish current

I need to complete three task in one button click. its look like on button click called SaveQuote
1) Hide Adview
2) Make Screenshot of Layout and Save it
3) Show Adview

Now I have implemented method for do above three task in my java as like below

else if(menuItem.getItemId() == R.id.save_image) {
adView.setVisibility(View.GONE);
saveQuote();
adView.setVisibility(View.VISIBLE);


But I am facing issue that ad always staying visible. If I use on ViewGone method and saveQuote method than its working fine, but if I add VISIBLE method than its not hiding my adview.

Note : I am not getting any error for same. I just need to know how can I achieve above three task via one button click

My saveQuote method is like below

private void saveQuote(){
String id=getQuote(mItemIndx).get(KEY_ID);
View v1=null;

List<Fragment> activeFragments=getSupportFragmentManager().getFragments();
for(Fragment fragment:activeFragments){

QuoteCard cardFrag=(QuoteCard)fragment;
if(cardFrag!=null&&cardFrag.mId.equals(id)){
v1=cardFrag.getCardView();

}
}
TextView textView = (TextView)v1.findViewById(R.id.textAuthorSign);
textView.setVisibility(TextView.VISIBLE);
v1.setDrawingCacheEnabled(true);
Bitmap bitmap = Bitmap.createBitmap(v1.getDrawingCache());
v1.setDrawingCacheEnabled(false);
ImageLoader.getInstance().saveQuoteImage(bitmap);
Snackbar.make(v1,"Quote Saved",Snackbar.LENGTH_SHORT).show();
adView.setVisibility(View.VISIBLE);
}


I am getting error like below if set VISIBLE method on end of saveQuote

java.lang.NullPointerException: Attempt to invoke virtual method 'void com.google.android.gms.ads.NativeExpressAdView.setVisibility(int)' on a null object reference


Thanks

Answer

You can do something like this.

adView.setVisibility(View.GONE);
saveQuote();

now in your saveQuote() method after all your logic is set.. add last line..

adView.setVisibility(View.VISIBLE); make note that your adView should be defined globally and you have initialized your adVIew.

Comments