So the super comes from MingleActivity, which extends Activity.It keeps throwing an error at ActivityThread.performResumeActivity(IBinder, boolean). My Try/Catch simply throws a Java.lang.Nullpointerexception error, so not really getting a lot of help there. It just keeps asking me to edit the source path.
package mingle.mix;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.Animation.AnimationListener;
import android.widget.TextView;
import android.widget.Toast;
public class MingleSpalshActivity extends MingleActivity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.spalsh);
try
{
startAnimating();
}
catch (Exception e)
{
// this is the line of code that sends a real error message to the log
Log.e("ERROR", "ERROR IN CODE: " + e.toString());
// this is the line that prints out the location in
// the code where the error occurred.
e.printStackTrace();
}
}
private void startAnimating() {
// Fade in top title
TextView logo1 = (TextView) findViewById(R.id.title_text);
Animation fade1 = AnimationUtils.loadAnimation(this, R.anim.fade_in);
logo1.startAnimation(fade1);
// Transition to Main Menu when bottom title finishes animating
fade1.setAnimationListener(new AnimationListener() {
public void onAnimationEnd(Animation animation) {
// The animation has ended, transition to the Main Menu screen
startActivity(new Intent(MingleSpalshActivity.this, MingleGameActivity.class));
MingleSpalshActivity.this.finish();
//Toast toast = Toast.makeText(getApplicationContext(), "A TOAST", Toast.LENGTH_SHORT );
//toast.show();
}
public void onAnimationRepeat(Animation animation) {
}
public void onAnimationStart(Animation animation) {
}
});
}
#Override
protected void onPause() {
super.onPause();
// Stop the animation
TextView logo1 = (TextView) findViewById(R.id.title_text);
logo1.clearAnimation();
}
#Override
protected void onResume()
{
super.onResume();
// Start animating at the beginning so we get the full splash screen experience
startAnimating();
}
}
Can we see the onResume() in MingleActivity?
Why are you wrapping the call to startAnimating() in a try/catch block when the method throws no Exception?
Related
I made a splash activity before my app's main activity. It has a movieview and an animated imageview. I have two problems with the imageview:
Before the fade-in animation starts the image is visible.
During the animation a see the frames. ( And it is not because of the emulator, I also tested it on a Sony Xperia SP.)
My java:
package com.koostamas.tbbt;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.VideoView;
public class SplashActivity extends Activity {
private ImageView circle;
private Animation anim;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
VideoView loading = (VideoView)findViewById(R.id.videoView_loading);
circle = (ImageView) findViewById(R.id.imageView_circle);
loading.setVideoPath("android.resource://com.koostamas.tbbt/raw/splash_loading");
loading.setZOrderOnTop(true);
loading.start();
anim = AnimationUtils.loadAnimation(this, R.anim.fade_in);
}
#Override
public void onWindowFocusChanged (boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (hasFocus)
circle.startAnimation(anim);
}
Thread thread = new Thread(){
#Override
public void run() {
// TODO Auto-generated method stub
try {
sleep(5000);
startActivity(new Intent(getApplicationContext(), MainActivity.class));
finish();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
};
{
thread.start();
}
}
Please help me solve these problems. Thanks in advance.
Instead of using the onWindowFocusChanged register on the videoView's setOnCompletionListener. there you can start your animation.
To call the next activity use :
new Handler().postDelayed(new Runnable() {
public void run()
{ startActivity(new Intent(getApplicationContext(), MainActivity.class));
finish(); }
} , animationTime);
I'm trying to start a very simple jWebSocket Client on Android and connect it to my local server. I'm using the JWC class from the demo together with jWebSocket 1.0 beta 8 and Android 4.0.3, my code looks like this:
import org.jwebsocket.api.WebSocketClientEvent;
import org.jwebsocket.api.WebSocketClientTokenListener;
import org.jwebsocket.api.WebSocketPacket;
import org.jwebsocket.client.token.BaseTokenClient;
import org.jwebsocket.kit.WebSocketException;
import org.jwebsocket.token.Token;
import android.app.Activity;
import android.content.Context;
import android.content.IntentFilter;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import cased.smids.communication.JWC;
public class TasksActivity extends Activity implements WebSocketClientTokenListener {
Spinner spinner;
Button btn_Start;
/** Called when the activity is first created. */
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
this.setContentView(R.layout.main);
JWC.init();
spinner = (Spinner)findViewById(R.id.sp_Task);
btn_Start = (Button)findViewById(R.id.btn_Start);
ArrayAdapter<CharSequence> adapter =
ArrayAdapter.createFromResource(
this,
R.array.Tasks,
android.R.layout.simple_spinner_item
);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
btn_Start.setOnClickListener(new View.OnClickListener() {
public void onClick(View src) {
switch (src.getId()) {
case R.id.btn_Start:
if (spinner.getSelectedItem().toString().equals("Connect")) {
try {
System.out.println("connecting manually...");
JWC.open();
} catch (WebSocketException e) {
e.printStackTrace();
}
}
default:
break;
}
}
});
}
#Override
protected void onResume() {
super.onResume();
System.out.println("* opening... ");
try {
JWC.addListener(this);
JWC.open();
} catch (WebSocketException ex) {
System.out.println("* exception: " + ex.getMessage());
}
}
#Override
protected void onPause() {
System.out.println("* closing... ");
try {
JWC.close();
JWC.removeListener(this);
} catch (WebSocketException ex) {
System.out.println("* exception: " + ex.getMessage());
}
super.onPause();
}
public void processClosed(WebSocketClientEvent arg0) {
System.out.println("closed");
}
public void processOpened(WebSocketClientEvent arg0) {
System.out.println("opened");
}
public void processOpening(WebSocketClientEvent arg0) {
System.out.println("opening");
}
public void processPacket(WebSocketClientEvent arg0, WebSocketPacket arg1) {
System.out.println("packet");
}
public void processReconnecting(WebSocketClientEvent arg0) {
System.out.println("reconnecting");
}
public void processToken(WebSocketClientEvent arg0, Token arg1) {
System.out.println("token");
}
}
so basically it's just a spinner and a button. For now, all I want to do is connect to my local jWebSocketServer. The demo-app (the .apk package from the website, if I import the code eclipse tells me to remove many "#Overwrite" before it compiles the code - after that same "bug" occurs) works with my server so it has to be the code. Right now all I get is "connecting..." and about 0.1s later "closed". Every time.
btw. the app has the right INTERNET and ACCESS_NETWORK_STATE so that shouldn't be a problem.
i will be grateful for any help.
Cheers
Turns out, BaseTokenClient.open() is catching all exceptions and doing nothing about it (silent fail). In my case - NetworkOnMainThreadException. Mystery solved.
I am displaying a progress bar using Async task class and simulatneously in parallel operation , i want to retrieve a string array from a function of another class that takes some time to return the string array.
The problem is that when i place the function call in doing backgroung function of AsyncTask class , it gives an error in Doing Background and gives the message as cant change the UI in doing Background ..
Therefore , i placed the function call in post Execute method of Asynctask class . It doesnot give an error but after the progress bar has reached 100% , then the screen goes black and takes some time to start the new activity.
How can i display the progress bar and make the function call simultaneously.??plz help , m in distress
here is the code
package com.integrated.mpr;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class Progess extends Activity implements OnClickListener{
static String[] display = new String[Choose.n];
Button bprogress;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.progress);
bprogress = (Button) findViewById(R.id.bProgress);
bprogress.setOnClickListener(this);
}
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch(v.getId()){
case R.id.bProgress:
String x ="abc";
new loadSomeStuff().execute(x);
break;
}
}
public class loadSomeStuff extends AsyncTask<String , Integer , String>{
ProgressDialog dialog;
protected void onPreExecute(){
dialog = new ProgressDialog(Progess.this);
dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
dialog.setMax(100);
dialog.show();
}
#Override
protected String doInBackground(String... arg0) {
// TODO Auto-generated method stub
for(int i = 0 ;i<40;i++){
publishProgress(5);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
dialog.dismiss();
String y ="abc";
return y;
}
protected void onProgressUpdate(Integer...progress){
dialog.incrementProgressBy(progress[0]);
}
protected void onPostExecute(String result){
display = new Logic().finaldata();
Intent openList = new Intent("com.integrated.mpr.SENSITIVELIST");
startActivity(openList);
}
}
}
You can't dismiss the dialog in doInBackground() - even dismissing a dialog needs the UI task. Move dialog.dismiss() to onPostExecute() of the AsyncTask.
Hello StackOverflow Users,
I am new to android and trying to develop a game in which I use a
1) Main class to redirect (like a menu.. new game, options, help, exit etc..)
2) A surfaceview class
3) A thread to handle drawing on canvas.
I have added an exit button on the main class.
However after playing the game i.e. drawing the objects and using them, when i redirect to my Main class and try to exit; the main screen disappears but the view and threads aren't destroyed.
This is the main class.
package com.tgm.welcome;
import com.tgm.R;
import com.tgm.main.GThread;
import com.tgm.main.TGMActivity;
import com.tgm.options.OptionsMain;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;
public class Welcome_Act extends Activity {
ImageView game, exit, options;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.welcome);
game = (ImageView) findViewById(R.id.newGame);
options = (ImageView) findViewById(R.id.options);
exit = (ImageView) findViewById(R.id.exit);
game.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
gotogame();
}
});
options.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
goto_opt();
}
});
exit.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
exit_game();
}
});
}
public void gotogame() {
Intent game = new Intent(Welcome_Act.this, TGMActivity.class);
startActivity(game);
}
public void goto_opt() {
Intent opt = new Intent(Welcome_Act.this, OptionsMain.class);
startActivity(opt);
}
public void exit_game() {
System.exit(0);
}
}
PLEASE HELP TO REMOVE THE GAMESCREEN FROM THE STACK THAT ANDROID MAINTAINS.
Thanks..
Using System.exit(0) is not advised in android. It doesnt guarantee finishing the Activity.
Instead of
public void exit_game() {
System.exit(0);
}
Use:
public void exit_game() {
Welcome_Act.finish();
}
Just call finish on the activity you want to remove from the stack.. it does the work you want..
In my application i get image from server and those image build animation.this all things are gone be right way and i create method for it.this is the method::
package com.animation;
import java.io.InputStream;
import java.net.URL;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.widget.Button;
import android.widget.ImageView;
public class animation extends Activity {
Button Buttona;
AnimationDrawable animation;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ImageView img = (ImageView) findViewById(R.id.simple_anim);
animation = new AnimationDrawable();
try {
for(int i=0;i<54;i++)
{
xyz("girl000",i);
}
animation.setOneShot(false);
} catch (Exception e) {
}
img.setBackgroundDrawable(animation);
img.post(new Starter());
}
public void xyz(String str,int x)
{
try {
Bitmap bitmap = BitmapFactory.decodeStream((InputStream) new URL(
"http://201.109.115.111/MRESC/images/test/girl/"+"girl000"+x+".png")
.getContent());
Drawable frame =new BitmapDrawable(bitmap);
animation.addFrame(frame, 50);
} catch (Exception e) {
}
}
class Starter implements Runnable {
public void run() {
animation.start();
}
}
}
now my problem is it is take much time to load image from server so simply i plan to use asyncTask. but problem is i cant get judgment that how can i do this?
can you give me example(Note : i know asyncTask and use already but problem is passing argument as per my xyz() method declare)
Thanks
nik
Here is the code:
Note that the loop now is in the background thread
After each loop, you publish the progress to setup the animation frame
At the very end, you run onPostExecute to run the remaining code
Note, that this is just a skeleton and rough sketches, you need to understand and debug it if there is any problem. I haven't run the code yet
public class Animation extends Activity {
Button Buttona;
AnimationDrawable animation;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
animation = new AnimationDrawable();
AsyncTask asyncTask =
new AsyncTask() {
#Override
protected Void doInBackground(Void... params) {
try {
// Execute this whole loop in background, so it doesn't
// block your UI Thread
for(int i=0;i<54;i++) {
xyz("girl000",i);
}
} catch (Exception e) {
return null;
}
}
public void xyz(String str,int x) {
try {
Bitmap bitmap = BitmapFactory.decodeStream((InputStream) new URL(
"http://201.109.115.111/MRESC/images/test/girl/"+"girl000"+x+".png")
.getContent());
// publish progress so that the bitmap is set on the UI Thread
publishProgress(bitmap);
} catch (Exception e) {
// handle error
}
}
#Override
protected void onProgressUpdate(Bitmap... result) {
// handle the progress update to add the animation frame
Bitmap bitmap = result[0];
Drawable frame =new BitmapDrawable(bitmap);
animation.addFrame(frame, 50);
}
#Override
protected void onPostExecute(Void result) {
if(result != null) {
// execute the rest of your instruction after the loop is over here
animation.setOneShot(false);
ImageView img = (ImageView) findViewById(R.id.simple_anim);
img.setBackgroundDrawable(animation);
img.post(new Starter());
} else {
// handle error
}
}
};
asyncTask.execute();
}
class Starter implements Runnable {
public void run() {
animation.start();
}
}
}