beeware / beeware/toga

On Android, MainWindow.size is (0, 0) until after startup method is complete

Open
#2,274 2 comments 0 reactions 0 assignees View on GitHub
android bug
Dominant language
Python
Stars
5.4k
Forks
827
Avg merge
9h 45m
Merged PRs (30d)
58

Description

### Discussed in https://github.com/beeware/toga/discussions/2273
via @cozimus

The following minimum working example work differently on windows and android.
```
import toga
from toga.style import Pack
from toga.style.pack import COLUMN

class Application(toga.App):
def startup(self):
self.main_window = toga.MainWindow(title=self.formal_name)
self.btn = toga.Button("click here", on_press=self.my_func)
main_box = toga.Box(style=Pack(flex=1, direction=COLUMN))
main_box.add(self.btn)
self.main_window.content = main_box
self.my_func()
self.main_window.show()

def my_func(self, widget=None):
self.btn.text = self.main_window.size

def main():
return Application("Application", "com.example")

if __name__ == "__main__":
app = main()
app.main_loop()
```
On windows the button text change when the application is started, and it shows the real window dimension (e.g. (640,480)), while on android when the application is started it shows (0,0). However when I press the button, `my_func` works ok and it gives the real window size.

Contributor guide

Open the contributing guide

Research direction

Start with the provided minimal example, especially startup(), MainWindow.size, and show(), and compare when the size becomes available on Android versus Windows. Trace the Android startup and window-sizing path; the issue is done when MainWindow.size reports the real dimensions during startup rather than (0, 0), while preserving the later button behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, python
Domain
mobile
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.