如何使用函数变量的值更新实例变量?

时间:2018-06-03 08:26:45

标签: java android global-variables

我刚开始在android工作室编程过去几个月,我一直想知道,我可以用函数中的变量值更新实例变量的值吗?为了使这更清楚

JAVA CODE

public class MapsActivity extends AppCompatActivity implements OnMapReadyCallback {
private FusedLocationProviderClient fusedLocationProviderClient;
              double latitudine, longitudine;
              Location currentLocation;
              Location newLocation;


Task location1 = fusedLocationProviderClient.getLastLocation();
              location1.addOnCompleteListener(new OnCompleteListener() {
              @Override
              public void onComplete(@NonNull Task task) {
              if (task.isSuccessful()) {
                 currentLocation = (Location) task.getResult();


Toast.makeText(MapsActivity.this,""+currentLocation.getLatitude(),
Toast.LENGTH_LONG).show();

Toast.makeText(MapsActivity.this,""+currentLocation.getLongitude(),
Toast.LENGTH_LONG).show();

   newLocation = currentLocation ;
            }else{
                Toast.makeText(MapsActivity.this,"no way",Toast.LENGTH_LONG).show();
            }
        }
    });

我只是想在项目的其他地方使用存储在currentLocation中的值,但我该怎么做呢?

0 个答案:

没有答案