Android - banner add UI issue

95 views Asked by At

I have two activities in my application, I have implemented banner add in my First Activity. when I come back from Second Activity to First Activity getting some UI issues I paused add in onPause and resuming in onResume but still getting same UI issue. See the attachment for reference.

enter image description here

Here is my code:

public class HomeActivity extends Activity implements OnClickListener {
    private Button addFriend, friendList;

    private AuthPreferences authPreferences;
    private ProgressDialog progressDialog;

    private Button requests;
    private AdView adView;

    List<User> list = new ArrayList<User>();

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.home_main);

        checkNetwork();

        addFriend = (Button) findViewById(R.id.Addfriend);
        friendList = (Button) findViewById(R.id.Friendlist);
        requests = (Button) findViewById(R.id.Request);

        addFriend.setOnClickListener(this);
        friendList.setOnClickListener(this);
        requests.setOnClickListener(this);

        startBackGoundService();

        // Adds code
        // http://www.androidbegin.com/tutorial/integrating-new-google-admob-banner-interstitial-ads/
        adView = (AdView) this.findViewById(R.id.adView);
        adView.loadAd(AdRequestUtil.getAdRequest());
    }

    private void checkNetwork() {
        // Check for n/w connection
        if (!NetworkService.isNetWorkAvailable(HomeActivity.this)) {
            AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(HomeActivity.this);
            // set title
            alertDialogBuilder.setTitle("Warning");
            alertDialogBuilder.setMessage("Check your network connection and try again.");
            // set dialog message
            alertDialogBuilder.setCancelable(true).setNegativeButton("Ok", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                }
            });
            // create alert dialog
            AlertDialog alertDialog = alertDialogBuilder.create();

            // show it
            alertDialog.show();
        }

    }

    private void startBackGoundService() {
        final AuthPreferences authPreferences = new AuthPreferences(getApplicationContext());
        Intent intent = new Intent(getApplicationContext(), TrackService.class);
        if (authPreferences.isHideChecked()) {
            stopService(intent);
        } else {
            startService(intent);
        }
    }

    @Override
    public void onClick(View v) {
        if (R.id.Addfriend == v.getId()) {
            Intent intent = new Intent(getApplicationContext(), AddFriendActivity.class);
            startActivity(intent);
        }
        if (R.id.Friendlist == v.getId()) {
            checkNetwork();
            getFriendsList();
        }
        if (R.id.Request == v.getId()) {
            checkNetwork();
            final ProgressDialog progressDialog = new ProgressDialog(HomeActivity.this);
            progressDialog.setMessage("Getting requests Please wait..");
            progressDialog.setCancelable(true);
            progressDialog.setProgressStyle(android.app.ProgressDialog.STYLE_SPINNER);

            GetFriendsRequestsTask friendsRequestsTask = new GetFriendsRequestsTask(progressDialog, this, true);
            friendsRequestsTask.execute();
        }

    }

    private void getFriendsList() {
        final ProgressDialog progressDialog = new ProgressDialog(HomeActivity.this);
        progressDialog.setMessage("Getting friends Please wait..");
        progressDialog.setCancelable(true);
        progressDialog.setProgressStyle(android.app.ProgressDialog.STYLE_SPINNER);

        GetFriendsTask getFriendsTask = new GetFriendsTask(progressDialog, this);
        getFriendsTask.execute();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public void onPause() {

        super.onPause();
        if (progressDialog != null){
            progressDialog.dismiss();
        }
        adView.pause();
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (R.id.signout == item.getItemId()) {
            checkNetwork();
            final ProgressDialog progressDialog = new ProgressDialog(HomeActivity.this);
            progressDialog.setMessage("User signout is in progress, please wait...");
            Log.i("User signout", "User signout is in progress");
            progressDialog.setCancelable(true);
            SignOutUtil.signOut(progressDialog, getApplicationContext());

            return true;
        }

        else if (R.id.aboutApp == item.getItemId()) {
            startActivity(new Intent(getApplicationContext(), AboutActivity.class));
        }

        else if (R.id.settings == item.getItemId()) {
            startActivity(new Intent(getApplicationContext(), SettingsActivity.class));
        }

        return super.onOptionsItemSelected(item);
    }

    @Override
    protected void onResume() {
        super.onResume();
        adView.resume();
        authPreferences = new AuthPreferences(getApplicationContext());
        String accessToken = authPreferences.getAccessToken();

        if (accessToken == null && authPreferences.getUserId() == 0) {
            Intent intent = new Intent(getApplicationContext(), MainActivity.class);
            startActivity(intent);
        }
    }

    @Override
    public void onBackPressed() {
        authPreferences = new AuthPreferences(this);
        if (authPreferences.isUserSignedIn())
            moveTaskToBack(true);
    }

}
0

There are 0 answers