Solved

create multi screen app

Posted on 2012-03-25
15
552 Views
Last Modified: 2012-03-26
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
Comment
Question by:jagguy
  • 8
  • 5
  • 2
15 Comments
 

Author Comment

by:jagguy
ID: 37764060
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
 
LVL 47

Expert Comment

by:for_yan
ID: 37764105
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
 

Author Comment

by:jagguy
ID: 37764120
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
 

Author Comment

by:jagguy
ID: 37764135
this gives the error  @Override however the app doesnt work when clicking buttn to go to next screen
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37764136
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
 
LVL 47

Expert Comment

by:for_yan
ID: 37764138
Maybe that is the isssue - I'm using 4.0.3
0
 
LVL 47

Assisted Solution

by:for_yan
for_yan earned 375 total points
ID: 37764153
close screenopne screen
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Comment

by:jagguy
ID: 37764208
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
 

Author Comment

by:jagguy
ID: 37764283
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
 
LVL 47

Expert Comment

by:for_yan
ID: 37764286
>Also how do I go back?

What that means ?
0
 
LVL 8

Assisted Solution

by:santhanasamy
santhanasamy earned 125 total points
ID: 37764298
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
 
LVL 8

Expert Comment

by:santhanasamy
ID: 37764324
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
 
LVL 47

Accepted Solution

by:
for_yan earned 375 total points
ID: 37764325
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
 
LVL 47

Assisted Solution

by:for_yan
for_yan earned 375 total points
ID: 37764358
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
 
LVL 47

Expert Comment

by:for_yan
ID: 37764367
In 233 looks even better than in 403:
andr233_openandr233_close
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
base64 decode encode 12 96
mockito example issue 8 35
Java Jpanels and Jframe 8 20
Old GPS chip on Samsung Tab 4 - Kit Kat? 2 18
Once again I push the limits of my phone.  An introduction to the Android Google Now Launcher.
You should read OS supplied guidelines before developing. I can't stress that enough. The guidelines will help you understand the reasons mobile app developers do what they do.  Apple is very particular when they review appstore submissions.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now