1. Are you ready for the Galaxy S20? Here is everything we know so far!

Create a new Activity or update view of existing activity?

Discussion in 'Android Development' started by andypaul1, Dec 24, 2012.

  1. andypaul1

    andypaul1 Lurker
    Thread Starter

    I am very new to android development. I am working on developing an app and I am not sure when should I use a new activity and when should I update the existing view.

    For example, lets say I have a view that shows a multiple choice question.Now, when the user selects his choices and clicks on say "Evaluate", I want to show the same question view but along with the right answers and explanations for each option. So does that mean, I should send an Intent upon a click on Evaluate or I should just update the view (i am not sure how)?

    If I send an intent and show a new screen, how can the user go back to the next question without displaying the answers?
    If I don't create an new activity, how can I update the existing view that is already displayed?

    I guess I am just confused about the flow. Please pardon me if my question doesn't make any sense.

    thanks!
     



    1. Download the Forums for Android™ app!


      Download

       
  2. jonbonazza

    jonbonazza Android Expert

    For your example, it would be best to use the same Activity, but just update the content of the Activity's Views.

    Activities can generally be thought of as windows in a traditional window manager. They should be used to separate logical steps in an application's use.
     
    andypaul1 likes this.
  3. andypaul1

    andypaul1 Lurker
    Thread Starter

    Thank you for your suggestion, jon.
    Any pointers on how to update an existing view that is already being displayed? I come from Java Swing world where I can simply add/remove components from a container in the event thread and the view is updated automatically. Or I just update the model (such as for a JTable) and call fireTableDataChanged, which updates the view.

    How does this work in Android app? As I understand the view is described in a hardcoded XML file, so how do I update it dynamically?

    thank you!
     
  4. jonbonazza

    jonbonazza Android Expert

    You can really do the same thing in Android, but it is better practice to create all of the UIs up front and either show/hide various controls depending on the state, or simply create your layouts in seperate xml files and use the setContentView() method to swap between them.
     
    andypaul1 likes this.
  5. andypaul1

    andypaul1 Lurker
    Thread Starter

    ok, thank you again.
     
Loading...
Similar Threads - Create Activity update
  1. RicardoM
    Replies:
    1
    Views:
    257
  2. My project
    Replies:
    9
    Views:
    497
  3. grizmixstir
    Replies:
    3
    Views:
    682
  4. kdmoore
    Replies:
    3
    Views:
    843
  5. cwg01
    Replies:
    3
    Views:
    2,430
  6. kumaranil13k
    Replies:
    4
    Views:
    875
  7. 5g Moto Android 11
    Replies:
    2
    Views:
    1,750
  8. Muhammad Faizan Ali Khan
    Replies:
    2
    Views:
    548
  9. App Update
    Replies:
    0
    Views:
    399
  10. Mehak Gul
    Replies:
    1
    Views:
    397

Share This Page

Loading...