【问题标题】:Unable to change from one activity to another(page gets reloaded)on in Android studio无法在 Android Studio 中从一个活动更改为另一个活动(页面重新加载)
【发布时间】:2018-03-24 18:16:46
【问题描述】:

相同的活动在单击按钮后重新加载,该按钮原本是用于另一个活动,但在第一次执行时工作正常。代码很正常很基础但是不知道问题所在

public void init() {
    ImageButton driver = (ImageButton) findViewById(R.id.driver);
    driver.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent login = new Intent(MapsActivity.this, Driverlogin.class);
            startActivity(login);
        }
    });
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maps);
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        checkLocationPermission();
    } // Obtain the SupportMapFragment and get notified when the map is ready to be used. SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() .findFragmentById(R.id.map); mapFragment.getMapAsync(this); init(); } 
}

【问题讨论】:

  • 我们希望看到code is normal and basic 这个。另外,如果您有错误日志,请分享它们
  • @shashi sekhar 请添加您的普通代码和基本代码
  • 更新了我的问题,请检查。
  • 没有错误日志。应用程序很好并且正在运行

标签: android android-intent android-activity reload


【解决方案1】:
public void init() 
{ 
    ImageButton driver=(ImageButton)findViewById(R.id.driver); 
    driver.setOnClickListener(new View.OnClickListener() { 

        @Override 
        public void onClick(View view) 
        { 
            Intent login=new Intent(MapsActivity.this,Driverlogin.class); 
            startActivity(login); 
        } 
    });
}

@Override 
protected void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState); setContentView(R.layout.activity_maps); 

    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) 
    { 
        checkLocationPermission(); 
    } 
    // Obtain the SupportMapFragment and get notified when the map is ready to be used. 
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() .findFragmentById(R.id.map); mapFragment.getMapAsync(this); init(); 
} 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多