【发布时间】:2015-09-17 20:38:18
【问题描述】:
我有一个登录活动,其中嵌套了一个扩展 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 中也没有任何内容。
【问题讨论】:
标签: java android broadcastreceiver android-button