I'm making an async request with retrofit, on the middle of request i minimize the app and crash the app...
My log error:
java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
at android.support.v4.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1842)
at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1860)
at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:650)
at android.support.v4.app.BackStackRecord.commit(BackStackRecord.java:609)
at br.com.ole.oleconsignado.util.ActivityUtils.replaceFragmentToActivityWithBackStack(ActivityUtils.java:109)
at br.com.ole.oleconsignado.ui.fragment.init.LoginFragment.notifyGetProspectSuccess(LoginFragment.java:410)
at br.com.ole.oleconsignado.ui.presenter.LoginPresenter$4.onSuccess(LoginPresenter.java:91)
at br.com.ole.oleconsignado.ui.presenter.LoginPresenter$4.onSuccess(LoginPresenter.java:88)
at br.com.ole.oleconsignado.network.RestCallback.onResponse(RestCallback.java:24)
at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run(ExecutorCallAdapterFactory.java:68)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6165)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:778)
Here it's the method I call if the request return success:
ActivityUtils.replaceFragmentToActivityWithBackStack(getFragmentManager(), IncompleteStatusFragment.newInstance(mLogin.getCustomerId(), mCustomer, prospect, mLogin), R.id.container_login);
Can someone help me?
That is obvious, if you minimize the app then you won't be able to replace the fragment as your app is not in focus & throw java.lang.IllegalStateException. you should probable maintain a flag & in onResume of your activity if that flag is true then replace the fragment.
like
#Override
public void onPause() {
mIsActivityVisible = false;
}
#Override
public void onResume() {
mIsActivityVisible = true;
if(mShouldReplaceFragmentOnResume) {
mShouldReplaceFragmentOnResume = false;
// replace fragment
}
}
// On Success response
onSuccessOfYourCall() {
if(mIsActivityVisible) {
//replace fragment
} else {
mShouldReplaceFragmentOnResume = true;
}
}
Related
Why the debug was giving me this?
everything is works fine i just did not understand why Eventbus giving me this??
can someone please help me? so much thanks
it just bothering me that i have a problem with my codess
This is the Log.
E/EventBus: Could not dispatch event: class
com.creamydark.Izone.JoYuri.YuriActionMessage to subscribing class
class com.creamydark.musilization.MainActivity
java.lang.IndexOutOfBoundsException: Index: 5, Size: 5
at java.util.ArrayList.get(ArrayList.java:437)
at com.ashokvarma.bottomnavigation.BottomNavigationBar.selectTabInternal(BottomNavigationBar.java:530)
at com.ashokvarma.bottomnavigation.BottomNavigationBar.selectTab(BottomNavigationBar.java:477)
at com.ashokvarma.bottomnavigation.BottomNavigationBar.selectTab(BottomNavigationBar.java:467)
at com.creamydark.musilization.MainActivity.onPageSelected(MainActivity.java:455)
at androidx.viewpager.widget.ViewPager.dispatchOnPageSelected(ViewPager.java:1941)
at androidx.viewpager.widget.ViewPager.scrollToItem(ViewPager.java:686)
at androidx.viewpager.widget.ViewPager.setCurrentItemInternal(ViewPager.java:670)
at androidx.viewpager.widget.ViewPager.setCurrentItemInternal(ViewPager.java:631)
at androidx.viewpager.widget.ViewPager.setCurrentItem(ViewPager.java:612)
at com.creamydark.musilization.MainActivity.eventMessage(MainActivity.java:204)
at java.lang.reflect.Method.invoke(Native Method)
at org.greenrobot.eventbus.EventBus.invokeSubscriber(EventBus.java:510)
at org.greenrobot.eventbus.EventBus.postToSubscription(EventBus.java:433)
at org.greenrobot.eventbus.EventBus.postSingleEventForEventType(EventBus.java:414)
at org.greenrobot.eventbus.EventBus.postSingleEvent(EventBus.java:387)
at org.greenrobot.eventbus.EventBus.post(EventBus.java:268)
at org.greenrobot.eventbus.EventBus.postSticky(EventBus.java:309)
at com.creamydark.musilization.BottomNavFragments.DetailSelectedAlphaFragment$1.onPostExecute(DetailSelectedAlphaFragment.java:111)
at com.creamydark.musilization.BottomNavFragments.DetailSelectedAlphaFragment$1.onPostExecute(DetailSelectedAlphaFragment.java:106)
at android.os.AsyncTask.finish(AsyncTask.java:771)
at android.os.AsyncTask.access$900(AsyncTask.java:199)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:788)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7660)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
D/EventBus: No subscribers registered for event class
org.greenrobot.eventbus.SubscriberExceptionEvent
This is my Subscriber from MainActivity.
#Subscribe(sticky = true )
public void eventMessage(YuriActionMessage message){
if (message.getAction() == "LOAD_PLAYER_UI") {
load_ExoPlayerUI();
} else if (message.getAction() == "LOAD_PLAYER_UI_PLAYPAUSE") {
load_PlayPauseBtn();
} else if (message.getAction() == "SET_CURRENT_VIEWPAGER_ITEM_DETAILFRAG") {
mact_IzoneVIewPager.setCurrentItem(5);
//EventBus.getDefault().removeStickyEvent(true);
} else if (message.getAction() == "SET_CURRENT_VIEWPAGER_ITEM_ALBUMFRAG") {
mact_IzoneVIewPager.setCurrentItem(1);
//EventBus.getDefault().removeStickyEvent(true);
}
}
This is the postEvent in my Fragment Attatch from MainActivity
public void initTrackModelList(long albumid){
IzoneGetTracksByAlbum izoneGetTracksByAlbum=new IzoneGetTracksByAlbum(this.getActivity(),albumid){
#Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
initRecyclerView();
EventBus.getDefault().postSticky(new YuriActionMessage("SET_CURRENT_VIEWPAGER_ITEM_DETAILFRAG"));
}
};
izoneGetTracksByAlbum.execute(mTrackModel);
}
this is my Event Message Model.
public class YuriActionMessage {
private String Action;
public YuriActionMessage(String action){
this.Action=action;
}
public String getAction() {
return Action;
}
public void setAction(String action) {
Action = action;
}
}
It's not about Eventbus. Sometimes errors in your code are thrown as Eventbus exceptions. Check your code. For example:
mact_IzoneVIewPager.setCurrentItem(5);
What does this mean, and can be fixed somehow?
Not crashing in my code, but in the super of the FragmentActivity, I can't figure out what I am doing wrong:
Fatal Exception: java.lang.IllegalArgumentException
at android.os.Parcel.readException(Parcel.java:1688)
at android.os.Parcel.readException(Parcel.java:1637)
at android.app.ActivityManagerProxy.isTopOfTask(ActivityManagerNative.java:5505)
at android.app.Activity.isTopOfTask(Activity.java:5983)
at android.app.Activity.onResume(Activity.java:1253)
at android.support.v4.app.FragmentActivity.onResume(FragmentActivity.java:485)
at nl.hgrams.passenger.activities.PSTimelineFragmentsActivity.onResume(PSTimelineFragmentsActivity.java:576)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1270)
at android.app.Activity.performResume(Activity.java:6788)
at android.app.ActivityThread.performNewIntents(ActivityThread.java:2844)
at android.app.ActivityThread.handleNewIntent(ActivityThread.java:2858)
at android.app.ActivityThread.-wrap15(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1575)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6186)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)
This is my onResume():
#Override
protected void onResume() {
super.onResume();
registerReceiver(addedPitstopBroadcastReceiver,
new IntentFilter("addedPitstop"));
if (PSApplicationClass.getInstance().pref.getUserId(PSTimelineFragmentsActivity.this) != null) {
renewSettings();
PSApplicationClass.getInstance().pref.setIsBackground(this, false);
if (PSApplicationClass.getInstance().pref.isRefetchUser(PSTimelineFragmentsActivity.this)) {
PSApplicationClass.getInstance().pref.setRefetchUser(PSTimelineFragmentsActivity.this, false);
MyFirebaseInstanceIDService.changeFirebaseToken(PSTimelineFragmentsActivity.this);
}
}
}
But it directly crashed at onResume, so it didn't pass to the next line. Also tried to reproduce me, but could not.
The user had a: LG G-Pad 8.3
am using firebase adapter in my project, now am integrate admob for rewarded ad it's working fine, but every video after completion it will throw following error...
java.lang.ClassCastException: com.google.ads.mediation.admob.AdMobAdapter cannot be cast to com.google.android.gms.ads.mediation.m
at com.google.android.gms.ads.internal.mediation.client.y.a(:com.google.android.gms.dynamite_dynamitemodulesa#12685008#12.6.85 (020306-197041431):262)
at com.google.android.gms.ads.internal.reward.c.b(:com.google.android.gms.dynamite_dynamitemodulesa#12685008#12.6.85 (020306-197041431):54)
at com.google.android.gms.ads.internal.reward.client.e.onTransact(:com.google.android.gms.dynamite_dynamitemodulesa#12685008#12.6.85 (020306-197041431):56)
at android.os.Binder.transact(Binder.java:380)
at com.google.android.gms.internal.ads.zzej.transactAndReadExceptionReturnVoid(Unknown Source)
at com.google.android.gms.internal.ads.zzahb.zze(Unknown Source)
at com.google.android.gms.internal.ads.zzahm.resume(Unknown Source)
at com.mopub.mobileads.GooglePlayServicesRewardedVideo$1.onResume(GooglePlayServicesRewardedVideo.java:84)
at com.mopub.common.MoPubLifecycleManager.onResume(MoPubLifecycleManager.java:83)
at com.mopub.common.MoPub.onResume(MoPub.java:257)
at com.coderays.realquiz.RealQuizDashBoard.onResume(RealQuizDashBoard.java:956)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1280)
at android.app.Activity.performResume(Activity.java:6096)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3011)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3063)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1361)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5343)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)
i will try this method https://stackoverflow.com/a/49959522/6477998 but still throw this error.
my gradle is..
dependencies {
implementation('com.mopub:mopub-sdk-interstitial:5.0.0#aar') {
transitive = true
}
// For rewarded videos. This will automatically also include interstitials
implementation('com.mopub:mopub-sdk-rewardedvideo:5.0.0#aar') {
transitive = true
}
implementation 'com.google.firebase:firebase-core:16.0.0'
implementation 'com.google.firebase:firebase-ads:15.0.1'
}
Which one to change, please give me a solution, am searching still 3 days but no improvement.
Advance thanx...
thanks, the error will be fixed after long time.
Step 1: i remove my adapter class GooglePlayServicesRewardedVideo.java from com.mopub.mobileads( if you are using GooglePlayServicesInterstitial.java please remove ).
Step 2: then, put admob mediation sdk into build.gradle i.e implementation 'com.mopub.mediation:admob:15.0.0.8'.
Step 3: then, remove the following lines in your rewarded display activity.
public class MainActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
MoPubRewardedVideos.initializeRewardedVideo(this);
MoPub.onCreate(this); // remove
// ...
}
#Override
public void onPause() {
super.onPause();
MoPub.onPause(this); // remove
}
#Override
public void onResume() {
super.onResume();
MoPub.onResume(this); // remove
}
// The following methods are required for Chartboost rewarded video mediation
#Override
public void onStart() {
super.onStart();
MoPub.onStart(this); // remove
}
#Override
public void onRestart() {
super.onRestart();
MoPub.onRestart(this); // remove
}
#Override
public void onStop() {
super.onStop();
MoPub.onStop(this); // remove
}
#Override
public void onDestroy() {
super.onDestroy();
MoPub.onDestroy(this); // remove
}
#Override
public void onBackPressed() {
super.onBackPressed();
MoPub.onBackPressed(this); // remove
}
}
Step 4 : syn your project, and take a build. Its working fine without error.
thanks.
We are implementing the salesforce live agent chat in our android mobile application. Everything works fine. But we have a corner case.
Initiating the chat -> Opens chat window -> click on close button in window immediately [ within fraction of second ]. App will be crashed. Below is the log obtained from crash.
Log :
java.lang.NullPointerException: Session is not active. Unable to
create LiveAgent Request. at
com.salesforce.android.service.common.utilities.validation.Arguments.checkNotNull(Arguments.java:75)
at
com.salesforce.android.chat.core.internal.liveagent.request.InternalChatRequestFactory.checkSessionIsActive(InternalChatRequestFactory.java:104)
at
com.salesforce.android.chat.core.internal.liveagent.request.InternalChatRequestFactory.createEndRequest(InternalChatRequestFactory.java:95)
at
com.salesforce.android.chat.core.internal.liveagent.handler.EndHandler.onEndingSessionState(EndHandler.java:109)
at
com.salesforce.android.chat.core.internal.liveagent.LiveAgentChatSession.onStateChanged(LiveAgentChatSession.java:177)
at
com.salesforce.android.chat.core.internal.liveagent.LiveAgentChatSession.onStateChanged(LiveAgentChatSession.java:54)
at
com.salesforce.android.service.common.utilities.lifecycle.LifecycleEvaluator.stateChanged(LifecycleEvaluator.java:304)
at
com.salesforce.android.service.common.utilities.lifecycle.LifecycleStateWatcher$1.run(LifecycleStateWatcher.java:73)
at android.os.Handler.handleCallback(Handler.java:751) at
android.os.Handler.dispatchMessage(Handler.java:95) at
android.os.Looper.loop(Looper.java:154) at
android.app.ActivityThread.main(ActivityThread.java:6688) at
java.lang.reflect.Method.invoke(Native Method) at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)
Is there any work around to overcome this issue. Help is appreciated.
This is how I'm doing it on my end. Hope this helps.
WebView wvBody = (WebView) findViewById(R.id.Chat_wvBody);
String url = "http://myweburl.com/chatx.html?m_email=" + accountInfo.getUserEmail() +
"&fname=" + accountInfo.getUserFirstName() +
"&lname=" + accountInfo.getUserLastName();
wvBody.getSettings().setJavaScriptEnabled(true);
wvBody.getSettings().setSaveFormData(false);
wvBody.getSettings().setDomStorageEnabled(true);
wvBody.getSettings().setBuiltInZoomControls(false);
wvBody.getSettings().setSupportZoom(false);
wvBody.getSettings().setLoadWithOverviewMode(true);
wvBody.getSettings().setUseWideViewPort(false);
if (Build.VERSION.SDK_INT >= 21) {
wvBody.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
}
wvBody.setWebViewClient(new WebViewClient() {
#Override
public void onPageStarted(WebView view, String url, Bitmap facIcon) {
avLoadingIndicatorView.setVisibility(View.VISIBLE);
tvNote.setVisibility(View.VISIBLE);
//SHOW LOADING IF IT ISNT ALREADY VISIBLE
}
#Override
public void onPageFinished(WebView view, String url) {
avLoadingIndicatorView.setVisibility(View.GONE);
tvNote.setVisibility(View.GONE);
//HIDE LOADING IT HAS FINISHED
webViewLoadingFinished = true;
}
});
if (savedInstanceState != null)
wvBody.restoreState(savedInstanceState);
else
wvBody.loadUrl(url);
wvBody.setBackgroundColor(0x00000000);
Im performing a write to a BLE characteristic, where with these specific devices certain characteristics are not writeable if the peripheral is still locked.
I'd like to simply provide a visual notification if this is called while the device is still locked, instead of the exception being thrown.
Here is the first part of the code which is from a custom library I've written for this application:
public Observable<byte[]> setInterval(int interval) {
if (!(interval > 0)) {
return Observable.error(new IllegalArgumentException("Interval must be greater than 0."));
}
byte[] bytes = Utils.formatIntToBytes(interval);
return mConnection.writeCharacteristic(Constants.INTERVAL, bytes)
.doOnError(throwable -> Log.d(TAG, "call: Error writing to the interval characteristic"))
.onErrorReturn(throwable -> {
return new byte[0];
});
}
And here is the method that uses the previous:
private void setInterval(int interval) {
mDevice.setInterval(interval)
.onErrorResumeNext(throwable -> {
return Observable.empty();
})
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Subscriber<byte[]>() {
#Override
public void onCompleted() {
}
#Override
public void onError(Throwable e) {
e.printStackTrace();
}
#Override
public void onNext(byte[] bytes) {
if (bytes != null) {
Toast.makeText(DeviceDetailActivity.this, Utils.formatResponse(bytes), Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(DeviceDetailActivity.this, "Seems to of been an error. Ensure the device is unlocked.", Toast.LENGTH_SHORT).show();
}
}
});
}
This was previously just an Action1, but I changed to a Subscriber to clearly show onError() has been implemented.
I've added a bunch of extra operators (onErrorReturn(), onErrorResumeNext()) in an attempt to prevent the exception.
Why is the exception still coming through?
EDIT: The stack trace:
java.lang.IllegalStateException: Exception thrown on Scheduler.Worker thread. Add `onError` handling.
at rx.android.schedulers.LooperScheduler$ScheduledAction.run(LooperScheduler.java:112)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: rx.exceptions.OnErrorNotImplementedException
at rx.internal.util.InternalObservableUtils$ErrorNotImplementedAction.call(InternalObservableUtils.java:386)
at rx.internal.util.InternalObservableUtils$ErrorNotImplementedAction.call(InternalObservableUtils.java:383)
at rx.internal.util.ActionSubscriber.onError(ActionSubscriber.java:44)
at rx.observers.SafeSubscriber._onError(SafeSubscriber.java:152)
at rx.observers.SafeSubscriber.onError(SafeSubscriber.java:115)
at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber.checkTerminated(OperatorObserveOn.java:276)
at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber.call(OperatorObserveOn.java:219)
at rx.android.schedulers.LooperScheduler$ScheduledAction.run(LooperScheduler.java:107)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: BleGattException{status=8, bleGattOperation=BleGattOperation{description='CHARACTERISTIC_WRITE'}}
at com.polidea.rxandroidble.internal.connection.RxBleGattCallback.propagateStatusErrorIfGattErrorOccurred(RxBleGattCallback.java:245)
at com.polidea.rxandroidble.internal.connection.RxBleGattCallback.access$100(RxBleGattCallback.java:26)
at com.polidea.rxandroidble.internal.connection.RxBleGattCallback$1.onCharacteristicWrite(RxBleGattCallback.java:110)
at android.bluetooth.BluetoothGatt$1.onCharacteristicWrite(BluetoothGatt.java:407)
at android.bluetooth.IBluetoothGattCallback$Stub.onTransact(IBluetoothGattCallback.java:279)
at android.os.Binder.execTransact(Binder.java:453)