我有一个登录活动,其中嵌套了一个扩展BroadcastReceiver以接收GCM注册令牌的类。我想在用户点击注册按钮后将注册令牌与用户名和电话号码一起存储。所以我在活动的Oncreate方法中实例化了按钮。所以在BroadcastReciver的OnRecieve方法中我有这个
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 :(得分:0)
原来我忘了启动BroadcastReceiver接收的服务。所以它与我的按钮无关。现在我已经开始我的服务了,我得到了一个响应,但我的位置是空的,因为总是在最后一个已知的位置,所以我必须解决这个问题:(