onaclov2000
onaclov2000

Reputation: 5841

Swap Layouts in Android App

I may be misunderstanding how the flow works with Android but my current app generates two icons when it is installed. I think I've figured out how this happened, I created a second activity in my project and when it's downloaded it installs the main application and the second activity.

I don't believe I need two activities, I just need to be able to load another view on top of the current view.I can't seem to figure out how to setcontentview (assuming that is the required change) outside of the oncreate routine.

I am attempting to swap the view in a separate function:

public static void FindSomething(Context context) 
{ 
    setContentView(R.layout.second_layout);

}

however I get a cannot make a static reference to a non static method...

Is my "new approach" correct, or was starting a new activity the correct method? If starting a new activity was correct, is it possible to not have a second icon downloaded?

My app is EECON for anyone interested in seeing that you get two icons when installing: https://market.android.com/search?q=eecon&so=1&c=apps

Here is how things ended up:

    <intent-filter>
      <action android:name="android.intent.action.MAIN" />
      <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>

Turned into this as a final result and it was fixed!

    <intent-filter>
      <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>

Upvotes: 0

Views: 698

Answers (1)

Martin Stone
Martin Stone

Reputation: 13007

You would normally have an activity per conceptual "page" of your application interface. This shouldn't result in multiple icons...

"An application usually consists of multiple activities that are loosely bound to each other"

[Edit: Removed bad guess]

Look in your AndroidManifest.xml file for intent-filter sections with action.MAIN and category.LAUNCHER. "All activities with filters that match this action and category are added to the list" used by the launcher. Make sure you only have this on your initial activity.

Upvotes: 2

Related Questions