Code for QuizSplashActivity:
package com.androidbook.triviaquiz;
import java.text.DateFormat;
import java.util.Date;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.view.animation.LayoutAnimationController;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
public class QuizSplashActivity extends QuizActivity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String rest="First Time Launched";
String launchd=DateFormat.getDateInstance().format(new Date());
String launcht=DateFormat.getTimeInstance().format(new Date());
String ldt=launchd+" "+launcht;
SharedPreferences set=getSharedPreferences(GAME_PREFERENCES,MODE_PRIVATE);
if(set.contains("lastLaunch"))
{rest=set.getString("lastLaunch", "default");
}
Log.i("LaunchInfo",rest);
SharedPreferences.Editor edit=set.edit();
edit.putString("lastLaunch",ldt);
edit.commit();
setContentView(R.layout.splash);
anime();
}
private void anime()
{TextView t1=(TextView)findViewById(R.id.TextViewTopTitle);
Animation f1=AnimationUtils.loadAnimation(this, R.anim.fade_in);
t1.startAnimation(f1);
TextView t2=(TextView)findViewById(R.id.TextViewBotTitle);
Animation f2=AnimationUtils.loadAnimation(this, R.anim.fade_in2);
//t2.startAnimation(f2);
// Animation fade2 =AnimationUtils.loadAnimation(this, R.anim.fade_in2);
//View.startAnimation(fade2);
t2.startAnimation(f2);
AnimationListener animListener=new AnimationListener() {
public void onAnimationEnd(Animation animation){
startActivity(new Intent(QuizSplashActivity.this,QuizMenuActivity.class));
QuizSplashActivity.this.finish();
}
public void onAnimationRepeat(Animation animation) {
}
public void onAnimationStart(Animation animation) {
}
};
f2.setAnimationListener(animListener);
Animation spinin=AnimationUtils.loadAnimation(this,R.anim.custom_anim);
LayoutAnimationController controller=new LayoutAnimationController(spinin);
TableLayout tb=(TableLayout) findViewById(R.id.tableLayout1);
for(int i=0;i<tb.getChildCount();i++)
{TableRow row=(TableRow) tb.getChildAt(i);
row.setLayoutAnimation(controller);
}
}
#Override
protected void onPause()
{super.onPause();
TextView t1=(TextView)findViewById(R.id.TextViewTopTitle);
t1.clearAnimation();
TextView t2 =(TextView)findViewById(R.id.TextViewBotTitle);
t2.clearAnimation();
TableLayout tb=(TableLayout) findViewById(R.id.tableLayout1);
for(int i=0;i<tb.getChildCount();i++)
{TableRow row=(TableRow) tb.getChildAt(i);
row.clearAnimation();
}
}
#Override
protected void onResume()
{super.onResume();
anime();
}
}
Code for QuizMenuActivity
package com.androidbook.triviaquiz;
import android.os.Bundle;
public class QuizMenuActivity extends QuizActivity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.menu);
}
}
After the animations in splash have played out (Specifically fade_in2) the QuizMenuActivity is supposed to be launched and splash finished. The Animations play out fine but the QuizMenuActivity doesn't seem to be launched. Playing around with the debugger/break points it seems the program flow never goes into onAnimationEnd (Animation animation) method. Though I might be wrong as I am pretty new with eclipse and android.
I've fixed the code based on the first reply and updated it.Now the listner is firing but after the start activity i get 'application has beenstopped unexpectedly.Please try again.Force Close'.Seems to be while in something called ZygoteInit$MethodAnd.
Is this the callstack:
tiv [Android Application]
DalvikVM[localhost:8612]
Thread [<3> main] (Running)
Thread [<13> Binder Thread #2] (Running)
Thread [<11> Binder Thread #1] (Running)
I think the callstacks supposed to be in the logcat but I'm getting 'Unable to open stack trace file '/data/anr/traces.txt': Permission denied' error log in logcat.
Also the appliction seems to crash before the the animation f2(which is what is being listened for) has been displayed.t2 never gets displayed.
-change manifest to this
-It solved my problem
-add dot in the beginning of activity name, not sure why or if it is necessary !
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.androidbook.triviaquiz7"
android:versionCode="1"
android:versionName="1.0">
<application
android:label="#string/app_name"
android:debuggable="true"
android:icon="#drawable/quizicon">
<activity
android:name=".QuizSplashActivity"
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=".QuizGameActivity"></activity>
<activity
android:name=".QuizSettingsActivity"></activity>
<activity
android:name=".QuizScoresActivity"></activity>
<activity
android:name=".QuizHelpActivity"></activity>
<activity
android:name=".QuizMenuActivity"></activity>
</application>
<uses-sdk
android:minSdkVersion="7" />
It seems you are adding the animation listener to the 'fade2' animation object. But that animation is not set to any view like
view.startAnimation(fade2);
Without starting the animation for a view the listener will not fire.
Related
I want to link my two activites by clicking on a button i have written the following code
public class IHBCAPTUREActivity extends Activity implements OnClickListener {
/** Called when the activity is first created. */
ImageView iv;
TextView tx;
Button b1;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
iv=(ImageView)findViewById(R.id.imageView1);
tx=(TextView)findViewById(R.id.textView1);
b1 = (Button) findViewById(R.id.button1);
b1.setOnClickListener(this);
}
#Override
public void onClick(View v) {
Intent calIntent;
**calIntent = new Intent(IHBCAPTUREActivity.this, LoginActivity.class);**
startActivity(calIntent);
}
}
error cumes in this line
calIntent = new Intent(IHBCAPTUREActivity.this, LoginActivity.class);
for LoginActivity.class that
LoginActivity cannot be resolved to a type . How to solve it?
here is the simple code how you can load one activity to another,
i have created two activities like this
FirstActivity.java
package com.rdc;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class FirstActivity extends Activity implements OnClickListener {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.first);
Button btnload = (Button) findViewById(R.id.btn);
btnload.setOnClickListener(this);
}
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i = new Intent(this, SecondActivity.class);
startActivity(i);
}
}
SecondActivity.java
package com.rdc;
import android.app.Activity;
import android.os.Bundle;
public class SecondActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.second);
}
}
and my manifest file is
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.rdc"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".FirstActivity"
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=".SecondActivity"
android:label="#string/app_name">
<intent-filter>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
try to implement this in your app and let me know if still any doubt is there.
Check whether you have declared LoginActivity in manifest file as:
<activity
android:name="your.package-name.LoginActivity" >
</activity>
You don't have anything wrong in code.
Its know issue that occurs randomly.
solution is to set the target to other API level in project->properties->android, then set it back.then clean you project once.
I think this will refresh the .classpath or some other files, not sure, but it works.
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
I have 2 Activities, one which is MainActivity and the other, ReadActivity.
Whenever I started ReadActivity from MainActivity, the Activity started but it shows nothing, just the android:label value in the Manifest file.
As I was investigating, I tried putting a Log in ReadActivity but I noticed that the OnCreate method isn't called as I forgot to override the method but when I put the "#Override" above the OnCreate method I get the followong error:
"The method OnCreate(Bundle) of type ReadActivity must override or implement a supertype method".
I don't get what's wrong with this line, I've crossed checked it so many times, compared the codes with other application's code but I just can't seem to override it. Can anyone help me? Below are the codes of my project.
MainActivity
package com.rangga.elearning.ngaji;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.View.OnClickListener;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity{
/** Called when the activity is first created. */
TextView txtLogo, txtVersion;
Button btnRead, btnIndex, btnAbout;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
//Typeface font = Typeface.createFromAsset(getAssets(), "assets/Schoolbell.ttf");
txtLogo = (TextView) findViewById(R.id.txtLogo);
txtVersion = (TextView) findViewById(R.id.txtVersion);
btnRead = (Button) findViewById(R.id.btnRead);
btnIndex = (Button) findViewById(R.id.btnIndex);
btnAbout = (Button) findViewById(R.id.btnAbout);
/* txtLogo.setTypeface(font);
txtVersion.setTypeface(font);
btnRead.setTypeface(font);
btnIndex.setTypeface(font);
btnAbout.setTypeface(font); */
btnRead.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
callIntent();
}
});
}
public void callIntent(){
Intent i = new Intent(this, ReadActivity.class);
startActivity(i);
}
}
ReadActivity
package com.rangga.elearning.ngaji;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Window;
import android.view.WindowManager;
public class ReadActivity extends Activity{
private static String TAG = "ReadActivity";
#Override
public void OnCreate(Bundle savedInstanceState){
Log.i(TAG, "ReadActivity dimulai");
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.read);
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.rangga.elearning.ngaji"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="7"
android:targetSdkVersion="7"
android:maxSdkVersion="8" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:screenOrientation="landscape" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ReadActivity"
android:label="Baca"
android:screenOrientation="landscape">
</activity>
</application>
</manifest>
Thank you.
onCreate() not OnCreate() . Besides, your manifest doesn't contain Intent information for your ReadActivity.
I am reading a android book for beginners, and while following on of the chapters I ran into a problem. The chapter is teaching about intents. I right now I have 2 layouts: main.xml, and digital_clock.xml. And in the AndroidManifest I have these lines of code:
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:label="#string/app_name"
android:name=".Chapter11Activity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".DigitalClockActivity" >
</activity>
</application>
Also I have the two Activity classes that correspond to the layouts:
Chapter11Activity:
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class Chapter11Activity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button a2 = (Button)findViewById(R.id.button1);
a2.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent myIntent = new Intent(v.getContext(), DigitalClockActivity.class);
startActivityForResult(myIntent, 0);
}
});
}
}
DigitalClockActivity:
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class DigitalClockActivity extends Activity {
public void OnCreate(Bundle sIS) {
super.onCreate(sIS);
setContentView(R.layout.digital_clock);
Button a1 = (Button) findViewById(R.id.button01);
a1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent replyIntent = new Intent();
setResult(RESULT_OK, replyIntent);
finish();
}
});
}
}
When I run the app on my phone and switch to the second activity it shows nothing at all. Am I defining something wrong in the AndroidManifest? The application seems very straight forward, but it is not working. I have check over to make sure I didn't type anything wrong. Is it because I am running a android 2.3.3 phone and using the 1.5 sdk, and something is not backwards compatible? Any answers are appreciated!
~Andrew
Method name in second activity should be onCreate not OnCreate.
To prevent typos like this in the future use #Override on methods that you are overriding:
#Override
public void OnCreate(Bundle sIS) {
// code here
}
Then if you make a typo, the compiler will tell about it.
i have read a lot about this but didnt come up with a solution.
this is my first android project.
i am trying yo open an activity from my main activity.
i have doubled check the names and the configuration files, but the startactivity() procedure fails.
debbuger shows runtime errror.
as u will c, the startactivity is called upon onclick event.
i am really stuck here dont know what else to do.
thanks a lot!
* this is the main activity **
package com.example.helloandroid;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class HelloworldActivity extends Activity {
/** Called when the activity is first created. */
private OnClickListener gtScoringListener = new OnClickListener() {
public void onClick(View v) {
Intent mintent = new Intent(HelloworldActivity.this ,imgScoring.class);
startActivity(mintent);
}
};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button button = (Button)findViewById(R.id.button1);
button.setOnClickListener(gtScoringListener);
}
}
* this is the target activity: *
package com.example.helloandroid;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class imgScoring extends Activity {
private OnClickListener backBtnListener = new OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(imgScoring.this, HelloworldActivity.class);
startActivity(intent);
}
};
private OnClickListener scoreBtnListener = new OnClickListener() {
public void onClick(View v){
TextView tv = (TextView)findViewById(R.id.editText1);
tv.setText(((Button)v).getText());
}
};
/** Called when the activity is first created. */
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Button button = (Button)findViewById(R.id.button1);
button.setOnClickListener(scoreBtnListener);
button = (Button)findViewById(R.id.Button01);
button.setOnClickListener(scoreBtnListener);
button = (Button)findViewById(R.id.Button03);
button.setOnClickListener(scoreBtnListener);
button = (Button)findViewById(R.id.Button02);
button.setOnClickListener(scoreBtnListener);
button = (Button)findViewById(R.id.Button04);
button.setOnClickListener(scoreBtnListener);
button = (Button)findViewById(R.id.button3);
button.setOnClickListener(backBtnListener);
setContentView(R.layout.imgscoring);
}
}
this is the androidmanifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.helloandroid"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="12" />
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".imgScoring"></activity>
<activity android:name=".HelloworldActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
You should've posted the stacktrace, but I assume the error is on this line in your target activity:
button.setOnClickListener(scoreBtnListener);
This will give you a NULL:
Button button = (Button)findViewById(R.id.button1);
because you haven't set a contentview in THAT activity, so there is nothing for findViewById() to return. You'll get a nullpointer when calling that setOnclickLIstener()
Try change class name from imgScoring to ImgScoring everywhere. Java is not allowing class name to start from small letter ;-)
And place setContentView(R.layout.imgscoring); just after your super.onCreate();
an anyone look at this simple code (?) and tell me what's wrong please?
I'm a complete beginner to android development and I don't understand why my application doesn't even start. I get an unexpected error.. : (
Here it is:
package applicationTest.ppr.com;
import android.app.Activity;
import android.os.Bundle;
import android.widget.LinearLayout;
public class MainClass extends Activity {
/** Called when the activity is first created. */
/*Global vars*/
public static LinearLayout lila;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
lila = (LinearLayout) findViewById(R.id.lilay);
setContentView(lila);
}
public void Shortoast(){new Game(this);}
public static LinearLayout returnLayout(){return lila;}
}
The program doesn't even launch, and I think it might have something to do with how I handle the LinearLayout and setContentView();
anyway thanks very much in advance!
Suggestion: keep it as simple as possible until you fix the issue!
Then you can concentrate on your business logic.
package applicationTest.ppr.com;
import android.app.Activity;
import android.os.Bundle;
import android.widget.LinearLayout;
public class MainClass extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.id.lilay);
}
}
Also, is your main activity mapped in the Android manifest?
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name="MainClass"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</activity>
--EDIT--
Do you have the lilay.xml file in your res/layout folder?