模拟器工作完全正常,但设备上的APK无法按预期工作

时间:2017-12-30 13:59:11

标签: java android android-fragments

我正在为学校模块构建一个应用程序, 在构建此应用程序时,我一直在使用2.3.3上的仿真器来测试所有更改/配置。

然而,现在我已经完成了应用程序,我已经构建了一个调试APK,并且在触摸图像按钮时我的一些片段上它完全冻结并说'#34;已停止"并给我选项"再次打开应用程序"。

有谁知道可能导致这种情况的原因是什么?

下面的代码摘录可以调查:

Mainactivity

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.ListFragment;
import android.view.Viewimport android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;


public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
}

@Override
public void onBackPressed() {
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    if (drawer.isDrawerOpen(GravityCompat.START)) {
        drawer.closeDrawer(GravityCompat.START);
    } else {
        super.onBackPressed();
    }
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;

}


@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    switch (item.getItemId()) {
        case R.id.action_settings:
            Intent intent = new Intent(this, MainActivity.class);
            startActivity(intent);
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }

}

@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
    // Handle navigation view item clicks here.
    int id = item.getItemId();

    if (id == R.id.mercedes) {
        BlankFragment blankFragment = new BlankFragment();
        FragmentManager manager = getSupportFragmentManager();
        manager.beginTransaction()
                .replace(R.id.mainLayout, blankFragment)
                .commit();

    } else if (id == R.id.audi) {
        audi blankFragment = new audi();
        FragmentManager manager = getSupportFragmentManager();
        manager.beginTransaction()
                .replace(R.id.mainLayout, blankFragment)
                .commit();

    } else if (id == R.id.bmw) {
        bmw blankFragment = new bmw();
        FragmentManager manager = getSupportFragmentManager();
        manager.beginTransaction()
                .replace(R.id.mainLayout, blankFragment)
                .commit();

    } else if (id == R.id.empportal) {
        employeeportal blankFragment = new employeeportal();
        FragmentManager manager = getSupportFragmentManager();
        manager.beginTransaction()
                .replace(R.id.mainLayout, blankFragment)
                .commit();

    } else if (id == R.id.empportalv2) {
        employeeportalv2 blankFragment = new employeeportalv2();
        FragmentManager manager = getSupportFragmentManager();
        manager.beginTransaction()
                .replace(R.id.mainLayout, blankFragment)
                .commit();

    }

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    return true;
}

public void e63(View view) {

    e63room e63 = new e63room();
    FragmentManager manager = getSupportFragmentManager();
    manager.beginTransaction().replace(R.id.mainLayout, e63)
            .commit();

}

public void gle63(View view) {

    gleroom gle63 = new gleroom();
    FragmentManager manager = getSupportFragmentManager();
    manager.beginTransaction().replace(R.id.mainLayout, gle63)
            .commit();

}

public void c63(View view) {

    mercedesamgroom mercedesamgroom = new mercedesamgroom();
    FragmentManager manager = getSupportFragmentManager();
    manager.beginTransaction().replace(R.id.mainLayout, mercedesamgroom)
            .commit();

}

public void rs3(View view) {

    rs3room rs3 = new rs3room();
    FragmentManager manager = getSupportFragmentManager();
    manager.beginTransaction().replace(R.id.mainLayout, rs3)
            .commit();

}



public void rs4(View view) {

    rs4room rs4 = new rs4room();
    FragmentManager manager = getSupportFragmentManager();
    manager.beginTransaction().replace(R.id.mainLayout, rs4)
            .commit();

}


public void rs5(View view) {

    rs5room rs5 = new rs5room();
    FragmentManager manager = getSupportFragmentManager();
    manager.beginTransaction().replace(R.id.mainLayout, rs5)
            .commit();

}

public void m3(View view) {

    m3room m3 = new m3room();
    FragmentManager manager = getSupportFragmentManager();
    manager.beginTransaction().replace(R.id.mainLayout, m3)
            .commit();
}

public void x6m (View view) {

    x6mroom x6m = new x6mroom();
    FragmentManager manager = getSupportFragmentManager();
    manager.beginTransaction().replace(R.id.mainLayout, x6m)
            .commit();

}

public void m6(View view) {

    m6room m6 = new m6room();
    FragmentManager manager = getSupportFragmentManager();
    manager.beginTransaction().replace(R.id.mainLayout, m6)
            .commit();

}

的AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:theme="@style/AppTheme.NoActionBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

我不知道究竟是什么导致了这个问题。

正在使用的设备是三星s8&amp;它也已在三星s6上测试过,但不起作用。

我已经测试了调试APK和发布APK任何帮助都将非常感谢这是一个应该在1月12日到期的分级工作

0 个答案:

没有答案