Android - 横幅添加UI问题

时间:2015-06-22 15:48:26

标签: android banner-ads

我的应用程序中有两个活动,我在第一个活动中实现了横幅添加。当我从第二个活动回到第一个活动获取一些UI问题时,我暂停添加onPause并在onResume中恢复,但仍然遇到相同的UI问题。请参阅附件以供参考。

enter image description here

这是我的代码:

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 个答案:

没有答案