0

Im deploying app which creates match schedule.

You have to type teams, then app create schedule and then you adding results and app shows sorted table with results.

In main activity i have object Tourney, which have method addResult(int homescore,int awayscore) - its adding results.

In main activity is Button, which starts ListActivity, where you can see remaining matches. After you click on match you can insert score of home and away team and match will be marked as played and moved from list.

My question is, how can i call method Tourney.addResult() from main activity if im at different activity?

Thank you.

n0hepe
  • 188
  • 1
  • 2
  • 11
  • 3
    **"how can i call method Tourney.addResult() from main activity if im at different activity?"** - Don't try to do this. One `Activity` shouldn't directly access any part of another `Activity`. Create some sort of common data storage mechanism (`SharedPreferences`, SQLite database etc) and have `Tourney` as a separate 'helper' class which can be accessed from both `Activities`. – Squonk Jan 30 '13 at 20:39

1 Answers1

4

google has an answer http://developer.android.com/guide/faq/framework.html#3

in short: it is not a good practice share objects between activities: activity can die and you never know if the reference is still valid and another activity. However you can create a singleton class in application (not activity) and get the instance to this class in any activity you want.

for more discussion refer to What's the best way to share data between activities?

Community
  • 1
  • 1
mishmashru
  • 459
  • 5
  • 8