2015-09-17 32 views
0

我有一个登录活动,它嵌套了一个扩展BroadcastReceiver以接收GCM注册令牌的类。我想在用户点击注册按钮后将注册令牌与用户名和电话号码一起存储。所以我实例化了活动的Oncreate方法中的按钮。所以在BroadcastReciver的OnRecieve方法我有这个Android按钮没有响应,Logcat中没有显示任何内容

signup.setOnClickListener(new View.OnClickListener() { 
       @Override 
       public void onClick(View view) { 
        try { 
         mLocationRequest = new LocationRequest(); 
         mLocationRequest.setInterval(10); 
         mLocationRequest.setFastestInterval(10); 
         mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY); 
         //mLocationRequest.setPriority(LocationRequest.PRIORITY_LOW_POWER); 
         //mLocationRequest.setSmallestDisplacement(0.1F); 

         //LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this); 
         //locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, (android.location.LocationListener) listener); 
         MyActivity maac = new MyActivity(); 
         maac.startReceivingLocationUpdates(); 


         Location mLastLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); 
         double latitude = mLastLocation.getLatitude(); 
         double longitude = mLastLocation.getLongitude(); 

         if ((text != null && name.getText().length() > 0 && tele.getText().length() > 0) && (latitude > 0 && longitude > 0) && (isInputValid(name) && isInputValid(tele))){ 
          namestring = name.getText().toString(); 
          telestring = tele.getText().toString(); 
          String la = String.valueOf(latitude); 
          String lo = String.valueOf(longitude); 
          SendLogin sendcreds = new SendLogin(); 
          sendcreds.execute(text, namestring, telestring, la, lo); 
          //set number to 1 if user has already signed up if not set it to 0 so they sign up 
          sharedPref = getSharedPreferences("data", MODE_PRIVATE); 
          number = sharedPref.getInt("isLogged", 0); 
          if(number == 0) { 
           //Open the login activity and set this so that next it value is 1 then this condition will be false. 
           SharedPreferences.Editor prefEditor = sharedPref.edit(); 
           prefEditor.putInt("isLogged", 1); 
           prefEditor.commit(); 
          } else { 
           //Open this Home activity 
           Intent intent = new Intent(Login.this, MainActivity.class); 
           startActivity(intent); 
          } 

         }else{ 
          Log.i("login!!!", "caution: empty login"); 
          Toast.makeText(getApplicationContext(), "complete all boxes!!!", Toast.LENGTH_SHORT).show(); 
          return; 
         } 

        }catch (NullPointerException npo){ 
         npo.printStackTrace(); 
         Log.i("oops-----", "location is null in my opinion"); 
        } 
       } 
      }); 

我有一个的AsyncTask类,也被嵌套在登录活动,送的凭据到服务器在一个单独的线程。但是,当我点击按钮什么也没有发生,logcat中没有任何东西。

回答

0

原来,我忘了启动我的BroadcastReceiver收到的服务。所以它与我的按钮无关。现在,我已经开始我的服务,我得到了一个响应,但我的位置为空,因为始终与最后一个已知的位置,所以我必须解决该问题:(