-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bugs on sample (and maybe library too) #2
Comments
The issue seems to occur even on other projects using this library. It's about permissions, but the idea is the same: to get the result from another Activity. |
Hi there, version 0.9 is out to address this issue. The error you have mentioned was indeed my fault, at least when starting from Activity. Starting it from fragment, however, requires a bit more work since orientation change recreates that Fragment, see here or example module for more information. Would you kindly try it in your case and let me know if the issue has been resolved? Thanks for the detailed information and certainly for that RxPermissions link! I should've googled it before creating my own rx permissions library. |
Is the fragment issue also fixed? |
I tested the sample with 0.9. 10-23 10:11:18.400 3745-3745/com.example.rxactivity E/AndroidRuntime: FATAL EXCEPTION: main |
Yes the fragment is supposed to be fixed, but I can see it still hasn't in your case. Let me gather more information to be more of help:
I actually don't use RxJava that much, but paired with RxAndroid, it can do some pretty amazing asynchronous operations. Kotlin, on the other hand, has pretty much totally changed how I code. It's great that you started, give it some time and you will see that Kotlin's syntax is far more powerful than Java's. |
About Kotlin, it has some good things, but it also has some disadvantages compared to Java. Java is clearer (less ambiguity than Kotlin). It is more open (overriding is enabled by default). It has more useful visibility modifiers (Kotlin lacks package modifier for classes, for example). Drives to be more efficient (Kotlin suggests to use fields using getters&setters, always, while on Java you can easily use fields when not needed). Less "junk" characters (Kotlin code has a lot of "?" and "!" because of null access). And some other things I forgot that got me annoyed with it. I will miss Java. I worked with it for a lot of years. Say, do you know perhaps about Rx as replacement for AsyncTask and AsyncTaskLoader? If so, can you please try to answer this: |
It seems that those 2 bugs aren't related to
Well that is the wisest sayings I've heard today, and there is certainly a truth in that. After all passion is what drives all of us in speaking these non-human languages. I do use |
About the sample, seems both fragment and activity examples work fine. About replacement to AsyncTask, I see you replied me there. Thanks. |
Can you please update the gradle file instructions ? It still says I should use the problematic 0.9 version. |
That actually is the way it is supposed to work. But I do admit it is another one of my fault for not spending much time in README. But let me explain it here: Version 0.9 isn't actually broken, it was just the example app. What kind of error are you getting from your build.gradle? |
So error is just any other result, even if it's a result that can be normally be returned... Does your library support getting the Intent data result (including a bundle) ? About issue with the repo, I thought it's an issue in both library and sample. You wrote it's just the sample, so ok. |
Following pattern of my answer in your StackOverflow post, let's use Observable as example again:
I'm actually very open about future development of my libraries. Just like this one, I thought this was the simplest form of starting an activity without having if else code in |
I don't say it doesn't work. Just that it's not an error. I don't like to "ride" on callbacks that don't have the correct term. I have issue with the app we work on, but this might be our code that has issues. However, even though the sample seems to work fine, I think that the dialogs you create are shown by using the previously destroyed activity. So you actually use the previously destroyed instance of MainActivity (memory leak) to handle the onActivityResult of the new one... If you used a TextView instead of dialog, you'd see that nothing will occur on the new instance of MainActivty, because the text was set on the old one instead. See why I think with Rx you have to be more careful than with Android... |
Tested with TextView. Got the same issue. |
Okay I can see your point, thank you for some amazing observation. I suppose it is fixable with activity/fragment instance check I'm currently working on. If not, then I'm afraid this library is doomed. |
Sorry I don't have enough experience with Rx to help you on this. |
I managed to fix this issue by passing newly created activity instance in But for now, would you kindly confirm that example module is working? Only focus on |
That's odd, I could have sworn it is working fine on AVD and my Pixel XL. I have just pushed another commit, please try it again. |
I think that the handling of the result should be set in the onCreate. Not in the "onClick". This is because "onCreate" is called before "onActivityResult", so it can be initialized there. "onClick" however is called only by the user.
Anyway, I have to leave this library now. I have other tasks. I might try this at home though. |
I understand, thank you for all your help! |
I got it: Your log seems to point to |
Here, add this TextView to your layout, just above the FrameLayout that has the id "container" :
Then, change the "onClick" code to have these lines:
If you don't change orientation when the NextActivity is opened, everything seems ok, because the MainActivity is still the same.
|
Oh I thought it was only second generation of Pixel that has those issues. Mine doesn't, but then again it's only about 3 months old. |
For me it doesn't work. |
Something is really weird here. I tried to debug the app, but something is wrong on my IDE/SDK because it fails to stop on the breakpoints I put. I tried on older version of the IDE, and on emulator and an older version of gradle . Still can't debug. During debug (after it worked), I noticed there is no reference to the real one. I can't access "this@MainActivity", unless I actually use it in code, which then causes memory leak. I then tried to show the bytecode of the MainActivity.kt. The code of startActivityForResult2 isn't there. There isn't even the "applog" text I've put. In fact, even the word "startActivityForResult2" isn't there... Please explain what is going on. This is very different from what I know on Java, and doesn't make sense to me at all. |
It's actually not that complicated, and no RxJava is involved this time. The last parameter of startActivityForResult2 (callback) is a function types that brings 4 values: Activity/Fragment (T), request code, result code, and nullable Intent. You may see it clearer in Java: But with Kotlin, that Activity/Fragment is the receiver of that function type. When you call Since Oh and all of them are have It isn't different at all than what you know in Java, but I suppose shorter syntax makes it look confusing at first glance. |
This brings so many questions:
To me it seems a lot of code here is hidden. |
Yes, I have accepted it as the price to pay to have shorter syntax. |
|
|
I completely forgot what this is all about... |
Hello old friend, back then we were leveraging RxJava and Kotlin for Android permission and activity results because we hate request codes LOL. But nowadays Android has a native I wish good luck to you and your career. |
OK thanks |
Steps:
Then it crashes.
Tested on Nexus 5x with Android O, OPR4.170623.009
I wanted to put logs, but I don't see anything related to the library or Android OS, that is related to this issue.
When using Fragment, I don't see a crash, but it's still an issue because as I see it, it's supposed to show a snackbar, yet it doesn't do anything.
Also, even without changing orientation, I see something else: if I don't choose "OK RESULT", I always see a snackbar saying there is an error. It doesn't matter what I do, I get this error:
"Activity with request code ... fails expected result code check."
The text was updated successfully, but these errors were encountered: