2015-11-02 53 views
1

想做的事:我想要在互聯網上檢查一個應用程序的開始,如果它沒有找到,然後點擊肯定按鈕它應該去設置WiFi & if用戶在無線上然後回到應用程序我想對話框被解僱和動畫開始其他它再次顯示如何互聯網對話框。在Oncreate()中的動畫不停止在android中

我做了什麼:我已經把在互聯網上查看對話框中的onResume()和動畫代碼在OnCreate中。

問題:我的應用程序,啓動時檢查Wifi連接,但它也是在連續性唯一的Internet連接後運行的OnCreate()的所有動畫代碼,而不是運行它的

的OnCreate代碼:

protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     overridePendingTransition(R.anim.grow_from_middle, R.anim.shrink_to_middle); 
     setContentView(R.layout.activity_csplogin); 
     getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN); 
     mobileEdit = (EditText) findViewById(R.id.mobileText); 
     nameEdit = (EditText) findViewById(R.id.nameText); 
     employerEdit = (EditText) findViewById(R.id.employerText); 
     noEmployerCheckbox = (CheckBox) findViewById(R.id.noEmployercheckboxid); 
     employerSpinner = (Spinner) findViewById(R.id.employer_spinner_id); 
     noEmployerLayout = (LinearLayout) findViewById(R.id.linearlayoutCheckbox); 

     init(); 


     if (myPrefs.getOrgValidated() == false) { 
      new OrganisationValidationTask(CSPLoginActivity.this).execute(); 
     } 



     isdeviceValidated = myPrefs.getIsDeviceValidated(); 
     isLoggedIn = myPrefs.getIsLogIn(); 
     if (isdeviceValidated) { 
      startLoginActivity(); 
     } 



      final RelativeLayout LoginBox = (RelativeLayout) findViewById(R.id.LoginBox); 

      LoginBox.setVisibility(View.GONE); 

      Animation animTranslate = AnimationUtils.loadAnimation(CSPLoginActivity.this, R.anim.translate); 
      animTranslate.setAnimationListener(new AnimationListener() { 

       @Override 
       public void onAnimationStart(Animation arg0) { 

       } 

       @Override 
       public void onAnimationRepeat(Animation arg0) { 
       } 

       @Override 
       public void onAnimationEnd(Animation arg0) { 

        LoginBox.setVisibility(View.VISIBLE); 
        Animation animFade = AnimationUtils.loadAnimation(CSPLoginActivity.this, R.anim.fade); 
        LoginBox.startAnimation(animFade); 

        showSingleChoice(); 
       } 

      }); 
      ImageView imgLogo = (ImageView) findViewById(R.id.imageView1); 
      imgLogo.startAnimation(animTranslate); 

      isdeviceValidated = myPrefs.getIsDeviceValidated(); 
      isLoggedIn = myPrefs.getIsLogIn(); 


      if (!isLoggedIn) { 
       // display login screen 

       if (Utils.isNetworkConnected(this)) { 

        if (isdeviceValidated) { 
         // to display user details 
//     displayUserDetails(); 

         if (!isMyServiceRunning()) { 
          Utils.startLocationPollerAndWakeupService(this); 
         } 

        } 
       } 
      } else if (isLoggedIn && isdeviceValidated) { 
       // skip login screen 
       if (!isMyServiceRunning()) { 
        Utils.startLocationPollerAndWakeupService(this); 
       } 
       startLoginActivity(); 

      } 

     } 

的onResume

@Override 
    protected void onResume() { 
     super.onResume(); 

      if(Utils.isNetworkConnected(this)) { 

      }else{ 
       showWifiAlert(); 
      } 
     } 

檢查Internet連接對話框

private void showWifiAlert(){ 
     new MaterialDialog.Builder(CSPLoginActivity.this) 

       .content("Unable to validate device as Internet not available") 
       .title("Alert !") 
       .positiveText("OK") 
       .negativeText("Cancel") 
       .callback(new MaterialDialog.ButtonCallback() { 
        @Override 
        public void onNegative(MaterialDialog dialog) { 
         finish(); 

        } 

        @Override 
        public void onPositive(MaterialDialog dialog) { 
         dialog.dismiss(); 
         startActivity(new Intent(android.provider.Settings.ACTION_WIFI_SETTINGS)); 
        } 
       }) 
       .cancelable(false) 
       .show(); 


    } 

請幫幫忙,如何實現我想做的事情。

+1

試着把你的'imgLogo.startAnimation(animTranslate);'Utils.isNetworkConnected(this)'裏面'循環 – Mohit

+0

@Mohit:它爲我工作。非常感謝 。你已保存了 。我也會請求你,請回答問題,而不是評論,以便它能幫助我們。 –

+0

您的歡迎...以及我不確定答案,所以我沒有發佈... – Mohit

回答

1

嘗試更換的onResume方法的代碼如下:

@Override 
    protected void onResume() { 
     super.onResume(); 

      if(Utils.isNetworkConnected(this)) { 
       imgLogo.startAnimation(animTranslate); 
      }else{ 
       showWifiAlert(); 
      } 
     } 

讓我知道這對你的作品。

+0

如果您發現此答案正確,請致電upvote。 – Sangeeta

+1

謝謝。我會 。 –