On Tue, Mar 22, 2016 at 9:07 AM, Ilan Tal <[email protected]> wrote:
> Hi Ytai, > I almost gave up on getting a reply from you, since my problem isn't > connected to the IOIO board as such but is an android problem. > > I have written tons of code in regular Java but android is a different > mind set. In regular Java I make a constructor to a dialog or whatever else > I want to use and then I call functions in the instantiated class. Here > things just come alive by themselves. > Well, not really. You're calling API methods to make those things happen. Whether you're constructing the objects explicitly or requesting them to be created from the framework is not such a big difference. Of course, like anything else, it is a learning curve, but luckily there's really good documentation on the Android developer website explaining all those things. I'd recommend you to take some time to go over those things, so you don't have to do much trial and error to get your app going. > > The problem with everything in a single file was that when the android > screen turned off, it would disconnect the IOIO board, but my timer would > keep counting. You can see my initial bias was to use a constructor and > then somehow start the IOIO - and stop the IOIO when I am finished. I had > no idea what exactly to call in "my1", assuming there is something in the > IOIOActivity which will start the board. The only thing I could find was > startActivity but that used new intent. > This has nothing to do with single file or not. Your activity typically gets stopped by the framework when the phone goes to sleep. That's just the way it is. The framework notifies your activity that it should stop by calling its onStop() method. What your activity does (by virtue of inheriting from IOIOActivity) is disconnect from the IOIO when that happens. It doesn't *have* to do that, though. As I said, if you make a copy of IOIOActivity and inherit from *it* instead, you can change its behavior, for example, to not disconnect from the IOIO in onStop(), but rather some other time, for example, if the user explicitly presses a disconnect button. This isn't a very good practice, strictly speaking, since Android really *does* want you to stop the application in onStop() and if you want to leave stuff running in the background, you should really use a service (e.g. IOIOService). But in practice it would probably work fine. BTW, I might be mis-remembering, but I feel like on my phone the app only gets paused (onPause()) when the screen turns off, hence keeping the IOIO connection alive. > > It is totally unclear to me why having the code in a separate file would > make any real difference. If I understand you correctly you are saying have > the loop going always, but perhaps have the code which it operates in a > separate object. Then I would never "start" or "stop" the IOIO itself but > only control what it is doing in a separate object. I can't see how that > would make any difference, since it is the card itself which is losing > connection. I thought that if I could somehow start and stop the card > itself, then it would no longer loose connection when the android screen > goes off. It isn't clear to me who is telling the IOIO to drop the > connection, and why. > No. It is not about a separate file or a separate object. IOIOActivity is explicitly telling the IOIO to connect at onStart() and disconnect at onStop(), and what I proposed is for you to change that. All I meant with my comment regarding a separate file is that if you want, you can define your IOIOLooper sub-class as a regular class (in a separate file) rather than an inner class of your IOIOActivity sub-class (just to make the code more readable, not a fundamental difference in functionality). > > Once I see what the answer is, it will probably look very simple but at > the moment it is all black magic. Somehow I need to get control and not > have the card drop the connection whenever the screen goes blank or some > other event. I looked at the source code for IOIOActivity and it didn't > give me much. That code is the interface and I need something which calls > it - something that does start and stop on the board itself. At least this > is what I think I need. > What calls it is the Android framework. You don't call onStart() and onStop() etc. directly. What these methods to (e.g. call the IOIOAndroidApplicationHelper.start(), etc.) is what makes the IOIO connect and disconnect etc. > > Thanks, > Ilan > > -- > You received this message because you are subscribed to the Google Groups > "ioio-users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at https://groups.google.com/group/ioio-users. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "ioio-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/ioio-users. For more options, visit https://groups.google.com/d/optout.
