簡體   English   中英

Android對暫停/恢復無響應

[英]Android not responding on pausing/resuming

我一直在我的應用程序中收到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輸入調度超時(正在等待發送非關鍵事件,因為正在發送...

我該如何解決。 讓我知道您是否需要完整的日志跟蹤。

我找到了解決方案。 我的問題是與谷歌播放服務的依賴關系。 依賴性編譯'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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM