Object Orientated Code
Author
Discussion

steve-V8s

Original Poster:

2,924 posts

278 months

Saturday 23rd October 2021
quotequote all
I am struggling a bit with Object Oriented code. Used Visual Basic a bit a long time ago but forgotten most of it.

If I call a sub in C or assembler (my preferred language) it does whatever is in that sub and then Returns to where it was. With, in this case code running under Android I call a different page and do something, when the user presses the back button it returns to the parent page and waits for something to happen, rather than returning to the place it was called from. Is that correct or am I missing something.

sociopath

3,433 posts

96 months

Saturday 23rd October 2021
quotequote all
There'll undoubtedly be someone with much more recent experience than me, but if you're calling a page then I'd guess you have to define the operation of the back button at that point, otherwise how does the page know where to return to?

Basically I reckon you aren't getting to the end of the sub call by pressing the back button

S13_Alan

1,393 posts

273 months

Saturday 23rd October 2021
quotequote all
You're also mixing up whatever way the Android framework works (I don't know to be honest) with the idea of OO code.

When you call a method (function) in Java it behaves exactly as it does in C, it does what you've asked and then returns to the point it was called. This is true whether that method was part of an instance of an object or it's a static (think global scope) method.

If though you add in an underlying framework that's doing things you don't understand (Android) and any multithreaded stuff, it becomes a lot more difficult to follow what's actually going on when an action is performed in any way.

Maybe if you've got a specific example someone who knows a bit more about Android can help figure out what's happening for you.

jesusbuiltmycar

5,135 posts

284 months

Saturday 23rd October 2021
quotequote all
S13_Alan said:
You're also mixing up whatever way the Android framework works (I don't know to be honest) with the idea of OO code.
^^^
this

For OO:
If your a 'C' programmer the OO version is something akin to a C Struct with a load of pointers-to-functions (member functions).

Each instance of an object you create gets its own data and when you call a member function a pointer to the instance (i.e. the structure) is passed as the first parameters as this/self/etc. allowing the member function to access the at a members of the instance..

Android Back Navigation
Most commercial Android devices have a hardware back button. The default behaviour for simple Apps is that when they launch the first page is displayed. This page is usually the "MainActivity" when you navigate to a new page a new "Activity" is created which gets placed on top of the existing Activity in a stack. When you hit the back button the current activity is removed from the stack and the previous one is displayed.

The Navigation / behavoiur of the back button can be changed and configured if you need to do something different.