我继续在我的应用程序中收到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商店中找到日志跟踪
ANR输入调度超时(等待发送非关键事件,因为......
我该如何解决这个问题。如果您需要完整的日志跟踪,请告诉我。
答案 0 :(得分:0)
我找到了解决方案。我发的是谷歌播放服务依赖项。依赖编译'com.google.android.gms:play-services:9.0.2'似乎存在一些问题。删除它并添加适当的依赖项解决了这个问题。在我的情况下,我添加了以下依赖项
com.google.android.gms:发挥服务,地图:9.0.2
<强> com.google.android.gms:玩服务-位置:9.0.2 强>
的 com.google.android.gms:玩服务-分析:9.0.2 强>