Get Display for a new Acitivity

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Get Display for a new Acitivity

Postby himym » Fri Jan 29, 2010 3:26 pm

My problem is, I have one basic activity, which has some output on the screen. This activity calls after a certain time an other activity, which also needs to display sth on the screen. The thing is, the text of the basic activity is shown, and disappears after the specified time, but the text of the second activity is not shown. there then is only a black screen.

Code for the Basic activity:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. public void onCreate(Bundle savedInstanceState) {
  3.  
  4.         super.onCreate(savedInstanceState);
  5.  
  6.         setContentView(R.layout.main2);
  7.  
  8.         new Handler().postDelayed(new Runnable(){
  9.  
  10.             public void run() {
  11.  
  12.                  /* Create an Intent that will start the Menu-Activity. */
  13.  
  14.                  Intent mainIntent = new Intent(Main.this,Second.class);
  15.  
  16.                  Second.this.startActivity(mainIntent);
  17.  
  18.             }
  19.  
  20.        }, 1000);
  21.  
  22.     }
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


Code of the second activity:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. public class Second extends Activity {
  3.  
  4. public void create(Bundle icicle)
  5.  
  6.         {
  7.  
  8.         super.onCreate(icicle);
  9.  
  10.        
  11.  
  12.         setContentView(R.layout.main);
  13.  
  14. }
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


I added the second one as followed into my xml-file:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.         <activity android:name=".TakePicture" />
Parsed in 0.000 seconds, using GeSHi 1.0.8.4


Can anybody help me please, how can I make the text of the second activity visible??

Tanks a lot
regards
himym
Developer
Developer
 
Posts: 33
Joined: Sun Oct 18, 2009 9:50 am

Top

...

Postby KarlKarlsom » Fri Jan 29, 2010 8:37 pm

First of all you your function name is wrong in the second activity. Because of this the setContentView of the second activity is not called and you don't see anything.

you used:
public void create(Bundle icicle)
should be:
public void onCreate(Bundle icicle)

Another thing is I wonder about this code:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.    Intent mainIntent = new Intent(Main.this,Second.class);
  3.  
  4.    Second.this.startActivity(mainIntent);
  5.  
  6.  
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


Try this (i don't see why second should call itself :)):
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.    Intent mainIntent = new Intent(this,Second.class);
  3.  
  4.    this.startActivity(mainIntent);
  5.  
  6.  
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


The rest seems to be OK.
Please tell me if it worked.
KarlKarlsom
Experienced Developer
Experienced Developer
 
Posts: 55
Joined: Mon Dec 14, 2009 8:40 pm

Postby himym » Sat Jan 30, 2010 11:52 am

you used:
public void create(Bundle icicle)
should be:
public void onCreate(Bundle icicle)

This was it. Now its running thanks.

Another thing is I wonder about this code:
Java:

Intent mainIntent = new Intent(Main.this,Second.class);
Second.this.startActivity(mainIntent);

Dont know why, but with your solution its not compiling, with mine its even running :)

Thank you
himym
Developer
Developer
 
Posts: 33
Joined: Sun Oct 18, 2009 9:50 am

Postby KarlKarlsom » Sat Jan 30, 2010 1:02 pm

Ups.
My fault. I somehow missed that you are in a Hanlder().
KarlKarlsom
Experienced Developer
Experienced Developer
 
Posts: 55
Joined: Mon Dec 14, 2009 8:40 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 10 guests