• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 567
  • Last Modified:

create multi screen app

Hi,

I am having trouble ceating a multi-screen ap in android/eclipse. I just want to clikc a button and another screen appears like

http://start-jandroid.blogspot.com.au/2011/01/android-multiple-screen-example.html

what happens is that the second screen opens on startup, I click the button and the app sems to close without error. The firsy screen never appears.

<activity android:name=".MyNewScreen" android:label="MyNewScreenLabel"> </activity>

I tried changing manifest file name back to the orginial, and then If I click on the button I get an error.
0
jagguy
Asked:
jagguy
  • 8
  • 5
  • 2
4 Solutions
 
jagguyAuthor Commented:
I also tried this and got an error at

Description      Resource      Path      Location      Type
The method onClick(View) of type new View.OnClickListener(){} must override a superclass method      MultScreenActivity.java      /multScreen/src/com/ms      line 32      Java Problem




http://www.mkyong.com/android/android-activity-from-one-screen-to-another-screen/
0
 
for_yanCommented:
I strictly followed theri instructopions and it works for me
Only Close button is a little bit smallfor the word - writes "Clos"
Otherewise all is OK.

Did you place this correctly after the closing fo the prveious actavity-
after</activity> :
<activity android:name=".MyNewScreen" android:label="MyNewScreenLabel"> </activity>
0
 
jagguyAuthor Commented:
MY error in in Main file appActivity onClick(View) of type new View.OnClickListener(){} must override a superclass

      public void onClick(View arg0) {

also this has a warning
final Context context = this;

I am using ver 2.2 as this is my phones versions
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
jagguyAuthor Commented:
this gives the error  @Override however the app doesnt work when clicking buttn to go to next screen
0
 
for_yanCommented:
I'm not sure I understan what you mean - I just have two activities - exactly pasted the code as they show - one is ANdroidMutipleScreenEasy another is MyNewScreen - eaxctly as they show, and the i repaced contents f main.xml and added my_new_screen.xml to the layout foleder, pasted form their screen ther also, and then add this line to Manifest - afeter that just ran it  - dodn't change anything form their code
0
 
for_yanCommented:
Maybe that is the isssue - I'm using 4.0.3
0
 
for_yanCommented:
close screenopne screen
0
 
jagguyAuthor Commented:
ok forget 4.03 as this is no good to me. My phone os 2.2 and it is a new phone .

Create this file in 2.2 . I did get this to work but I had to remove the @Overrides

http://www.mkyong.com/android/android-activity-from-one-screen-to-another-screen/

Also how do I go back?
0
 
jagguyAuthor Commented:
In the 1st example you got working what does this coe do because ti still works fine without it.

  public void setOb( AndroidMultipleScreenEasyActivity obA){
          this.ob=obA;
         }
0
 
for_yanCommented:
>Also how do I go back?

What that means ?
0
 
SanthanaTechnical LeadCommented:
Hi jagguy,

I checked the code from the link
http://start-jandroid.blogspot.com.au/2011/01/android-multiple-screen-example.html
It is working perfectly to me...

From your comment
what happens is that the second screen opens on startup, I click the button and the app sems to close without error. The firsy screen never appears.

It seems problem in your Manifest.xml
while launching the app from the laucher  "MyNewScreen" activity is launched first as "startup" of your application.
That means in manifest you might have setted this activity as "Launcher" .
That is why while pressing the button "CLOSE" from this activity simply closed the app.
Because there is no activity in the background..

Check your manifest.xml. It should be simillar to following ....
<activity
   android:name="com.example.AndroidMultipleScreenEasy"
   android:label="MyScreenLabel">
   <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
   </intent-filter>
</activity>

<activity
   android:name="com.example.MyNewScreen"
   android:label="MyNewScreenLabel">
</activity>
0
 
SanthanaTechnical LeadCommented:
Hi jagguy,

From the example link 1,
MyNewScreen.java
Following code is not at all used . You can remove that code...

 public void setOb( AndroidMultipleScreenEasyActivity obA){
          this.ob=obA;
}

and you  can remove setResult(RESULT_OK);. If you start the second activity MyNewScreen for result from the AndroidMultipleScreenEasy it will be usefull to send the result back to the activity AndroidMultipleScreenEasy .

AndroidMultipleScreenEasy.java
You can remove the use less object  creation....MyNewScreen obB=new MyNewScreen();

Also how do I go back?

Do you want go back to the previoud activity from the App2Activity ?

Then copy past the following code from the "MyNewScreen "  inside the oncreate() of "App2Activity "

  Button b = (Button) findViewById(R.id.btnClick2);
      b.setOnClickListener(new View.OnClickListener() {
         public void onClick(View arg0) {
              finish();
         }
      });

Change the main2.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/linearLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
 
    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="I&apos;m screen 2 (main2.xml)"
        android:textAppearance="?android:attr/textAppearanceLarge" />
      <Button android:id="@+id/btnClick2"
                    android:layout_width="100px"
                    android:layout_height="50px"
                    android:text="Close" />
</LinearLayout>
0
 
for_yanCommented:
And works perfectly for me also with 233

I just pasted their code and their XML

Only thing I changed - they by defaiule create the file called
AndroidMultipleScreenEasyActivity.java

I removed that one and created the new one
named
AndroidMultipleScreenEasy.java
in corresondedcne with their code name

and then what I also need to do and first forgot is to modify this name in the
AndroidManifest.xml file

Othere than that jsut added MyNewScreen.java with their code
and pasted main.xml and cretaed and pasted my_new_screen.xml

Other than that everything worked
0
 
for_yanCommented:
This is exact code which works for me with 233

package com.example3;

import android.app.Activity;
import android.os.Bundle;
import android.content.Intent;
import android.view.View;
import android.widget.Button;

public class AndroidMultipleScreenEasy2 extends Activity
{
 MyNewScreen obB=new MyNewScreen();
   public void onCreate(Bundle icicle)
   {
      super.onCreate(icicle);
      setContentView(R.layout.main);
      
      Button b = (Button) findViewById(R.id.btnClick);
      b.setOnClickListener(new View.OnClickListener() {
      
         public void onClick(View arg0) {
         // here i call new screen;
         Intent i = new Intent(AndroidMultipleScreenEasy2.this, MyNewScreen.class);
         startActivity(i);
         } 
      });
   }
}

Open in new window


package com.example3;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MyNewScreen extends Activity
{
 AndroidMultipleScreenEasy2 ob;
   public void onCreate(Bundle icicle)
   {
      super.onCreate(icicle);
      setContentView(R.layout.my_new_screen);
      Button b = (Button) findViewById(R.id.btnClick2);
      b.setOnClickListener(new View.OnClickListener() {
         public void onClick(View arg0) {
   setResult(RESULT_OK);
         finish();
         } 
      });
   }
   
   public void setOb( AndroidMultipleScreenEasy2 obA){
    this.ob=obA;
   }
}

Open in new window


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:orientation="vertical"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
>
<TextView
   android:layout_width="fill_parent" 
   android:layout_height="wrap_content"
   android:text="You are in the first Screen"
/>
<Button android:id ="@+id/btnClick"
   android:layout_width="150px"
   android:layout_height="50px"
   android:text="Open New Screen"
/>

</LinearLayout>

Open in new window



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:orientation="vertical" android:layout_width="fill_parent"
 android:layout_height="fill_parent">
 <TextView android:layout_width="fill_parent"
  android:layout_height="wrap_content" android:text="You are in the New Screen, press close for back to previous screen" />
 <Button android:id="@+id/btnClick2" android:layout_width="100px"
  android:layout_height="50px" android:text="Close" />

</LinearLayout>

Open in new window


<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="hello">Hello World, AndroidMultipleScreenEasy2Activity!</string>
    <string name="app_name">AndroidMultipleScreenEasy2</string>

</resources>

Open in new window



<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example3"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="10" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".AndroidMultipleScreenEasy2"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".MyNewScreen" android:label="MyNewScreenLabel"> </activity>

        
    </application>

</manifest>

Open in new window


andr_eclipse
0
 
for_yanCommented:
In 233 looks even better than in 403:
andr233_openandr233_close
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 8
  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now