Android在暂停/恢复方面没有响应



我一直在应用程序中获取ANR警报。当我的应用程序顶部打开其他某些应用程序,并且该应用程序关闭时,我会从应用程序中获得ANR。我没有在UI线程中进行任何网络操作或任何循环。还没有任何日志跟踪。以下是我的代码。

活动类:

public class AuthenticationActivity extends AppCompatActivity{
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_authentication);
    setupActionbar();
    String auth_page;
    if(getIntent().getExtras() != null)
        auth_page = getIntent().getExtras().getString("auth_page");
    else
        auth_page = "login";
    if(auth_page != null) {
        if (auth_page.equals("login")){
            getSupportFragmentManager().beginTransaction().replace(R.id.authentication_container, new LoginFragment()).commitAllowingStateLoss();
        }else if(auth_page.equals("signup")){
            getSupportFragmentManager().beginTransaction().replace(R.id.authentication_container, new RegisterationFragment()).commitAllowingStateLoss();
        }
    }
}
/**
 * Function to set the ToolBar as ActionBar
 */
private void setupActionbar() {
    setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
    setTitle("");
    if(getSupportActionBar() != null) {
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setDisplayShowHomeEnabled(true);
        getSupportActionBar().setHomeAsUpIndicator(IconUtils.getBackActionBarIcon(AuthenticationActivity.this));
    }
}

}

碎片类:

public class LoginFragment extends Fragment{
private EditText edtMobile;
private EditText edtPassword;
private TextView txtForgotPassword;
private Activity mActivity;
private MenuItem mMemuLogin;
@Override
public void onAttach(Context context) {
    super.onAttach(context);
    setHasOptionsMenu(true);
    mActivity = (Activity) context;
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View page = inflater.inflate(R.layout.fragment_login, container, false);
    findViews(page);
    return page;
}

//preparing and calling the login service
private void login() {
    // Login service call
}
//initialize the views
private void findViews(View page) {
}

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    mMemuLogin = menu.findItem(R.id.action_authentication_done).setTitle("Ride");
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.action_authentication_done) {
        login();
    }
    return super.onOptionsItemSelected(item);
}
}

我的应用程序中使用以下依赖关系

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'net.steamcrafted:materialiconlib:1.0.3'
compile files('libs/volley.jar')
compile 'com.drivemode:TypefaceHelper:1.1.0'
compile 'com.android.support:multidex:1.0.1'
compile('com.crashlytics.sdk.android:crashlytics:2.5.7@aar') {
    transitive = true;
}
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.google.android.gms:play-services:9.0.2'
compile 'com.pubnub:pubnub-android-debug:3.7.10'
compile 'com.google.code.gson:gson:2.2.4'
compile 'com.android.support:design:23.4.0'
compile 'com.android.support:cardview-v7:23.4.0'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.android.support:recyclerview-v7:23.4.0'
compile 'joda-time:joda-time:2.3'
compile 'me.dm7.barcodescanner:zbar:1.8.4'
compile 'com.google.firebase:firebase-messaging:9.0.2'
compile 'com.facebook.android:facebook-android-sdk:4.13.0'

}应用插件:'com.google.gms.google-services'

我的应用程序清单中使用的服务

<!-- [START firebase_service] -->
    <service
        android:name=".MyFirebaseMessagingService">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT"/>
        </intent-filter>
    </service>
    <!-- [END firebase_service] -->
    <!-- [START firebase_iid_service] -->
    <service
        android:name=".MyFirebaseInstanceIDService">
        <intent-filter>
            <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
        </intent-filter>
    </service>
    <!-- [END firebase_iid_service] -->

应用程序类

public class MyApplication extends Application  {
/**
 * Global request queue for Volley
 */
private RequestQueue mRequestQueue;
/**
 * A singleton instance of the application class for easy access in other places
 */
private static MyApplication sInstance;
public static final String TAG = MyApplication.class.getSimpleName ();
private Context mContext;
@Override
public void onCreate () {
    super.onCreate ();
    AnalyticsTrackers.initialize(this);
    AnalyticsTrackers.getInstance().get();
    Fabric.with(this, new Crashlytics());
    FacebookSdk.sdkInitialize(getApplicationContext());
    AppEventsLogger.activateApp(this);
    FacebookSdk.setIsDebugEnabled(true);
    FacebookSdk.addLoggingBehavior(LoggingBehavior.APP_EVENTS);
    sInstance = this;
    mContext=this;
    TypefaceHelper.initialize(this);
}
@Override
protected void attachBaseContext(Context base) {
    super.attachBaseContext(base);
    MultiDex.install(this);
}
@Override
public void onTerminate () {
    TypefaceHelper.destroy();
    super.onTerminate ();
}
/**
 * @return ApplicationController singleton instance
 */
public static synchronized MyApplication getInstance () {
    return sInstance;
}
public RequestQueue getRequestQueue () {
    // lazy initialize the request queue, the queue instance will be
    // created when it is accessed for the first time
    if(mRequestQueue == null) {
        mRequestQueue = Volley.newRequestQueue(getApplicationContext());
    }
    return mRequestQueue;
}

}

注意:在Play Store中找到一个日志跟踪

ANR输入派发时间(等待发送非钥匙事件,因为...

我该如何解决。请让我知道您是否需要完整的日志跟踪。

我找到了解决方案。我的问题是Google Play服务依赖性。依赖关系 compile'com.google.android.gms中似乎存在一些问题:play-services:9.0.2'。删除此问题并添加适当的依赖关系解决了问题。就我而言,我添加了以下依赖项

com.google.android.gms:Play-Services-Maps:9.0.2

com.google.android.gms:Play-Services-Location:9.0.2
com.google.android.gms:Play-Services-Analytics:9.0.2

最新更新