【问题标题】:Android button not responding and nothing showing in LogcatAndroid 按钮没有响应,Logcat 中没有显示任何内容
【发布时间】: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


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-12-19
      • 1970-01-01
      • 2016-04-01
      • 2014-09-29
      • 1970-01-01
      • 2020-03-24
      • 2014-07-21
      相关资源
      最近更新 更多