I can't pass splash to another activity - android

I have program that has splassh page I used intent to pass splash activity to my main activity folder but when I run my program it stop after my splash
and here is my splash class and manıfest xml and my logcat
package com.tesbih;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class Splash extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
Thread timer = new Thread(){
public void run(){
try{
sleep(5000);
}catch(InterruptedException e){
e .printStackTrace();
}finally{
Intent openStartingPoint = new Intent ("com.tesbih.TESBIHMAINACTIVITY");
startActivity(openStartingPoint);
}
}
};
timer.start();
}
}
and following my manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tesbih"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.tesbih.TesbihMainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.TESBIHMAINACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.tesbih.Splash"
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>
moreover here is my logcat
02-23 20:33:40.713: E/AndroidRuntime(5683)android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.tesbih.TESBIHMAINACTIVITY }

you can copy and paste the that shown in below
package com.tesbih;
import android.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class Splash extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
Thread timer = new Thread(){
public void run(){
try{
sleep(3000);
}catch(InterruptedException e){
e.printStackTrace();
}finally{
Intent i = new Intent (Splash.this,TesbihMainActivity.class);
startActivity (i);
}
}
};
timer.start();
}
}

start your activity like this,
Intent openStartingPoint = new Intent (Splash.this,TesbihMainActivity.class);
startActivity(openStartingPoint);
instead of Timer, you can use handler for splash as well.
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
Intent i = new Intent(SplashScreen.this, TesbihMainActivity.class);
startActivity(i);
// close splash
finish();
}
}, SPLASH_TIME_OUT);

android:name="com.tesbih.TesbihMainActivity"
You have above in manifest so you must change
("com.tesbih.TESBIHMAINACTIVITY"); to ("com.tesbih.TesbihMainActivity"); in splash.java

Related

i can't redirect to next registration page when i click on to SIGN IN button

basically am a java developer but now am developing an android app.In my app i can't redirect to the next page when i click on to SIGN IN button and here is my code
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.widget.Button;
public class MainActivity extends ActionBarActivity implements View.OnClickListener {
Button log,sign;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
log = (Button) findViewById(R.id.login);
sign = (Button) findViewById(R.id.signup);
log.setOnClickListener(this);
sign.setOnClickListener(this);
}
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch(v.getId()) {
case R.id.login:
break;
case R.id.signup:
Intent open = new Intent("com.example.eblood.Register");
startActivity(open);
break;
}
}
}
}
Here is my next page java code
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 Register extends Activity{
Button backlog,regg;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.register);
backlog = (Button) findViewById(R.id.linktologin);
regg = (Button) findViewById(R.id.register);
backlog.setOnClickListener((OnClickListener) this);
}
public void onClick (View v)
{
switch(v.getId()) {
case R.id.register:
break;
case R.id.linktologin:
Intent in = new Intent("com.example.eblood.MainActivity");
startActivity(in);
break;
}
}
}
Here is my manifest code.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.eblood"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.eblood.home"
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="com.example.eblood.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.example.eblood.MAINACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.example.eblood.Register"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.REGISTER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
and the error am getting is android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.example.eblood.Register }
And here is my home.java
package com.example.eblood;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class home extends Activity {
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_main);
Thread timer = new Thread(){
public void run(){
try{
sleep(2000);
} catch (InterruptedException e){
e.printStackTrace();
} finally {
Intent openMainActivity = new Intent("com.example.eblood.MAINACTIVITY");
startActivity(openMainActivity);
}
}
};
timer.start();}{
}
}
Try this..
If you use Intent open = new Intent("com.example.eblood.Register"); you will get ActivityNotFoundException change it as Intent open = new Intent(MainActivity.this,Register.class);
Change this
Intent open = new Intent("com.example.eblood.Register");
startActivity(open);
to
Intent open = new Intent(MainActivity.this,Register.class);
startActivity(open);
also
change this
Intent in = new Intent("com.example.eblood.MainActivity");
startActivity(in);
to
Intent in = new Intent(Register.this,MainActivity.class);
startActivity(in);
EDIT
Change this.
Intent openMainActivity = new Intent("com.example.eblood.MAINACTIVITY");
startActivity(openMainActivity);
to
Intent openMainActivity = new Intent(home.this,MainActivity.class);
startActivity(openMainActivity);

Cannot redirect to next page

Here is my Home.java code. It is not redirecting to next page, even if I change the intent to (home.this, MainActivity.class):
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class Home extends Activity {
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_main);
Thread timer = new Thread() {
public void run() {
try{
sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
Intent openMainActivity = new Intent("com.droid.mine.MainActivity");
startActivity(openMainActivity);
}
}
};
timer.start();}{
}
}
Here is my MainActivity.java code. I.e next page
I am getting the error as ClassCastException:
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 MainActivity extends Activity {
Button log,sign;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.register);
log = (Button) findViewById(R.id.register);
sign = (Button) findViewById(R.id.linktologin);
log.setOnClickListener((OnClickListener) this);
sign.setOnClickListener((OnClickListener) this);
}
public void onClick(View v) {
switch(v.getId()) {
case R.id.register:
break;
case R.id.linktologin:
Intent i = new Intent();
i.setClass(MainActivity.this,Register.class);
startActivity(i);
break;
}
}
}
Manifest is as follows:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.droid.mine"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.droid.mine.Home"
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=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name=".MAINACTIVITY" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Here is the logcat error:
04-21 15:59:07.156: I/ApplicationPackageManager(21341): cscCountry is not German : INS
04-21 15:59:07.273: D/dalvikvm(21341): GC_EXTERNAL_ALLOC freed 78K, 47% free 2860K/5379K, external 408K/517K, paused 95ms
04-21 15:59:09.648: W/dalvikvm(21341): threadid=9: thread exiting with uncaught exception (group=0x40018578)
04-21 15:59:09.710: E/AndroidRuntime(21341): FATAL EXCEPTION: Thread-10
04-21 15:59:09.710: E/AndroidRuntime(21341): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.droid.mine.MainActivity }
04-21 15:59:09.710: E/AndroidRuntime(21341): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1409)
04-21 15:59:09.710: E/AndroidRuntime(21341): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379)
04-21 15:59:09.710: E/AndroidRuntime(21341): at android.app.Activity.startActivityForResult(Activity.java:2827)
04-21 15:59:09.710: E/AndroidRuntime(21341): at android.app.Activity.startActivity(Activity.java:2933)
04-21 15:59:09.710: E/AndroidRuntime(21341): at com.droid.mine.Home$1.run(Home.java:21)
Here is my Register.java class
package com.droid.mine;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class Register extends Activity implements View.OnClickListener {
Button backlog,regg;
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
backlog = (Button) findViewById(R.id.loginn);
regg = (Button) findViewById(R.id.signup);
backlog.setOnClickListener(this);
}
public void onClick (View v)
{
switch(v.getId()) {
case R.id.loginn:
break;
case R.id.signup:
Intent in = new Intent();
in.setClass(Register.this,MainActivity.class);
startActivity(in);
break;
}
}
}
Firstly
Change where you intent with this:
Intent intent = new Intent(Home.this,MainActivity.class);
startActivity(intent);
Secondly
Just update your manifest with this:
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.droid.mine.Home"
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="com.droid.mine.MainActivity"
android:label="#string/app_name" >
</activity>
<activity
android:name="com.droid.mine.Register"
android:label="#string/app_name" >
</activity>
</application>
Use this as home activity
package com.example.pms;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.MotionEvent;
import android.widget.Toast;
public class SplashScreen extends Activity {
/*
* The thread to process splash screen events
*/
private Thread mSplashThread;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// splash screen view
setContentView(R.layout.activity_splash);
final SplashScreen mSplashScreen=this;
/*
* The thread to wait for splash screen events
*/
mSplashThread =new Thread(){
#Override
public void run(){
try {
synchronized(this){
// Wait given period of time or exit on touch
wait(3000);
}
}
catch(InterruptedException ex){
}
finish();
// Run next activity
startActivity(new Intent(getBaseContext(), MainActivity.class));
new Runnable() {
#Override
public void run() {
mSplashThread.stop();
}
};
}
};
mSplashThread.start();
}
/**
* Processes splash screen touch events
*/
#Override
public boolean onTouchEvent(MotionEvent event) {
if(event.getAction() == MotionEvent.ACTION_DOWN)
{
synchronized(mSplashThread){
mSplashThread.notifyAll();
}
}
return true;
}
}
you can use this code instead
replace
.MainActivity
with
com.droid.mine.MainActivity
while declaring in Manifest file.
//delay in ms
int DELAY = 1000;
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
#Override
public void run() {
Intent intent = new Intent(Home.this,MainActivity.class);
startActivity(intent);
}
}, DELAY);
Change your Intent to:
Intent openMainActivity = new Intent(Home.this, MainActivity.class);
startActivity(openMainActivity);
and in manifest file use:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.testapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.testapp.Home"
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=".MainActivity"
android:label="#string/app_name" >
</activity>
</application>
</manifest>
You need to register MainActivity and Register Activity in the manifest:
<activity android:name=".Mainactivity" />
<activity android:name=".Register" />
log.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
});
}
sign.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
Intent i = new Intent();
i.setClass(MainActivity.this,Register.class);
startActivity(i);
});
}
I hope this works:
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class Home extends Activity{
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_main);
Thread splashTimer = new Thread() {
public void run() {
try {
int splashTimer = 0;
while (splashTimer < 2000) {
sleep(100);
splashTimer = splashTimer + 100;
}
Intent intent;
intent = new Intent(Home.this, MainActivity.class);
startActivity(intent);
finish();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
Log.d("asd","dasd");
}
finally {
finish();
}
}
};
splashTimer.start();
}
}
Edit: Replace your manifest file with this, now I hope it works:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.droid.mine"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.droid.mine.Home"
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="com.droid.mine.MainActivity"
android:label="#string/app_name" >
</activity>
</application>
</manifest>

Splash and main activity error

Can someone please help. After the splash activity, the main activity isn't opening up. But if I put in any other intent filter name it works Just not the main activity. Thanks in advance!
SPLASH ACTIVITY:
package com.hellhog.tfreqpro;
import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
public class Splash extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.splash);
MediaPlayer mp = MediaPlayer.create(Splash.this, R.raw.smusic);
mp.start();
Thread pro = new Thread(){
public void run(){
try{
sleep(6000);
}catch (InterruptedException e){
e.printStackTrace();
}finally{
Intent yo = new Intent ("android.intent.action2.MAINACTIVITY");
startActivity(yo);
}
}
};
pro.start();
}
#Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
finish();
}
}
MAIN ACTIVITY:
package com.hellhog.tfreqpro;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
public class MainActivity extends Activity{
Button a, c;
Intent b, d;
#Override
protected 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.activity_main);
a= (Button) findViewById(R.id.tacan);
c= (Button) findViewById(R.id.flp);
a.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
b = new Intent ("android.intent.action.CONVERTER");
startActivity(b);
}
});
c.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
d = new Intent ("android.intent.action.NEWFLP");
startActivity(d);
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
MANIFEST:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.hellhog.tfreqpro"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="10" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.hellhog.tfreqpro.Splash"
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="com.hellhog.tfreqpro.MainActivity"
android:label="#string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action2.MAINACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.hellhog.tfreqpro.Converter"
android:label="#string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.CONVERTER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.hellhog.tfreqpro.Flightplan"
android:label="#string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.FLIGHTPLAN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.hellhog.tfreqpro.NewFLP"
android:label="#string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.NEWFLP" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
Try this in your Splash Activity..
Intent yo = new Intent (Splash.this, MainActivity.class);
startActivity(yo);
In your manifest file
<activity
android:name="com.hellhog.tfreqpro.MainActivity"
android:label="#string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action2.MAINACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
delete the following lines of intent filtter
<intent-filter>
<action android:name="android.intent.action2.MAINACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
Here is what working for me perfectly !
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE); // Removes title bar
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); // Removes notification bar
setContentView(R.layout.splashscreen);
// Start timer and launch main activity
IntentLauncher launcher = new IntentLauncher();
launcher.start();
}
private class IntentLauncher extends Thread {
#Override
/**
* Sleep for some time and than start new activity.
*/
public void run() {
try {
// Sleeping
Thread.sleep(SLEEP_TIME*1000);
} catch (Exception e) {
Log.e(TAG, e.getMessage());
}
// Start main activity
Intent intent = new Intent(SplashActivity.this,FullscreenActivity.class);
SplashActivity.this.startActivity(intent);
SplashActivity.this.finish();
}
}
Try to use below code..
public class SplashScreenextends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splashscreen);
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
// TODO Auto-generated method stub
finish();
Intent menu = new Intent(getBaseContext(), MainActivity.class);
startActivity(menu);
}
}, 3000);
}
}
It will set your SplashScreen for 3 seconds and then starts your mainactivity or whatever activity you want to start.MAy it helps you..

android.content.ActivityNotFoundException: No Activity found to handle Intent splash screen

I am having an issue with loading up a new intent after my splash screen. I have looked at questions relating to this exception but they all seem to be dealing with thing like google play or google maps not being referenced correctly this is not the case for me.
These are the related questions I have looked at
Not found activity to handle intent?
activity not found to handle intent
no activity found to handle intent
Below is my manifest code
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.main"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".Splash"
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=".HomePage"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.HOMEPAGE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".OrderPlaced"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.ORDERPLACED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
Here is the code for the class splash
package com.android.main;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class Splash extends Activity{
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
Thread timer = new Thread(){
public void run(){
try{
sleep(1000);
}catch(InterruptedException e) {
e.printStackTrace();
}finally{
Intent openStartingPoint = new Intent("com.android.main.HOMEPAGE");
startActivity(openStartingPoint);
}
}
};
timer.start();
}
#Override
protected void onPause() {
super.onPause();
finish();
}
}
And here is the class HomePage I am trying to load after the splash screen
package com.android.main;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
public class HomePage extends Activity {
/** Called when the activity is first created. */
TextView name;
EditText editName;
TextView drinks;
Spinner drinksSpinner;
TextView message;
CheckBox checkbox;
Button createOrderButton;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
createOrder();
}
public void createOrder(){
createOrderButton = (Button) findViewById(R.id.bCreateOrder);
createOrderButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
postInformationtoAPI();
}
private void postInformationtoAPI() {
goToOrderCompleted();
}
private void goToOrderCompleted() {
Intent intent = new Intent(HomePage.this , OrderPlaced.class);
HomePage.this.startActivity(intent);
Log.i("onClick", "trying to start new activity to change layout");
}
});
}
}
The app force quits after loading the splash screen and gives the following exception
03-14 22:32:33.553: E/AndroidRuntime(3166): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.android.main.HOMEPAGE }
Any help with this would be greatly appreciated
You have to differentiate the Intent's Constructor,
Intent openStartingPoint = new Intent("com.android.main.HOMEPAGE");
Which assume com.android.main.HOMEPAGE as Intent's action Filter. Which is not available in your application's android manifest.xml file. You have
<action android:name="android.intent.action.HOMEPAGE" />
which should be,
<action android:name="com.android.main.HOMEPAGE" />
OR just change it with,
Intent openStartingPoint = new Intent(Splash.this, HOMEPAGE.class);
<activity
android:label="#string/app_name"
android:name=".SplashScreen"
android:screenOrientation="landscape"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.android.main.HOMEPAGE"
android:screenOrientation="landscape"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen" >
<intent-filter >
<action android:name="com.android.main.HOMEPAGE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Also i would have a timer task to display splash screen
public class SplashScreen extends Activity{
Timer splashTimer;
SplashTimerHandler splashTimerHandler;
private boolean applicationPaused=false;
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
this.setSplash();
}
private void setSplash()
{
this.splashTimerHandler=new SplashTimerHandler();
this.splashTimer=new Timer();
this.splashTimer.schedule(this.splashTimerHandler, 0, 1000);
}
#Override
public void onPause()
{
super.onPause();
this.applicationPaused=true;
this.closeSplashTimer();
}
#Override
public void onResume()
{
super.onResume();
if(this.applicationPaused)
{
this.applicationPaused=false;
this.closeSplashTimer();
this.setSplash();
}
}
public class SplashTimerHandler extends TimerTask{
int splashTimerCounter=0;
#Override
public void run()
{
splashTimerCounter++;
if(splashTimerCounter>2)
{
runOnUiThread(splashTimeOver);
}
}
private Runnable splashTimeOver=new Runnable() {
#Override
public void run()
{
closeSplashTimer();
startHomeScreen();
}
};
}
protected void closeSplashTimer()
{
if(this.splashTimer!=null)
{
this.splashTimer.cancel();
this.splashTimer=null;
}
}
private void startHomeScreen()
{
this.closeSplashScreen();
startActivity(new Intent("com.android.main.HOMEPAGE"));
}
private void closeSplashScreen()
{
this.closeSplashTimer();
this.finish();
}
#Override
public boolean onKeyDown(int keycode, KeyEvent event)
{
if(keycode==KeyEvent.KEYCODE_BACK)
{
this.closeSplashScreen();
}
return true;
}
}

unable to send Broadcast from activity :android

hi friends i am unable to send Broadcast from one activity to other activity pls see my code below and help:
public class SendBroadcast extends Activity {
public static String BROADCAST_ACTION = "com.unitedcoders.android.broadcasttest.SHOWTOAST";
/* }
});
}
public void sendBroadcast(){
Intent broadcast = new Intent("com.unitedcoders.android.broadcasttest.SHOWTOAST");
this.sendBroadcast(broadcast);
//startActivity(broadcast);
}
}
Receiving side code:
public class ToastDisplay extends Activity {
private BroadcastReceiver mReceiver;
#Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
Log.i("!!!!!!!InchooTutorial#######$$$$","%%%%%%% msg_for_me");
ent
// String msg_for_me = intent.getStringExtra("some_msg");
//log our message value
Log.i("!!!!!!!InchooTutorial#######$$$$","%%%%%%% msg_for_me");
}
};
//registering our receiver
this.registerReceiver(mReceiver, intentFilter);
}
#Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
//unregister our receiver
this.unregisterReceiver(this.mReceiver);
}
}
Manifest.xml is:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.unitedcoders.android.broadcasttest"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="4" />
<uses-permission android:name="android.permission.BROADCAST_STICKY"/>
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".SendBroadcast"
android:label="#string/app_name">
<intent-filter>
nitedcoders.android.broadcasttest.SHOWTOAST" />
</application> </manifest>
Since the other activity is not running when u send broadcast u wont receive it.
If u want to receive broadcasts even when the activity is not running . Declare it in xml .
Here is the code for you. I hope this is what you want.
package com.pdd.Receiver;
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 ReceiverActivity extends Activity implements OnClickListener{
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button b=(Button) findViewById(R.id.button1);
b.setOnClickListener(this);
}
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i =new Intent("com.pdd.receiver.myaction");
sendBroadcast(i);
}
}
Receiver Class
package com.pdd.Receiver;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;
public class MyReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context arg0, Intent arg1) {
// TODO Auto-generated method stub
//Intent i=new Intent(MyReceiver.class,Second.class);
Intent i=new Intent(arg0,Second.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
arg0.startActivity(i);
}
}
Second Activity to display Toast
package com.pdd.Receiver;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Toast;
public class Second extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
Toast.makeText(getApplicationContext(), "This is second activity", 5000).show();
}
}
Manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.pdd.Receiver"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<receiver android:name="com.pdd.Receiver.MyReceiver">
<intent-filter>
<action android:name="com.pdd.receiver.myaction"></action>
</intent-filter>
</receiver>
<activity
android:name=".ReceiverActivity"
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=".Second"></activity>
</application>
</manifest>
If your SendBroadcast activity is created the broadcast will be send.
Then you start the second activity called ToastDisplay and in the onResume you register the BroadcastReceiver. But this is to late, the broadcast was already send, it will not stay in the system!
Try sending a stickybroadcast like:
sendStickyBroadcast(Intent)
Or declare the broadcastreceiver in the manifest but then you need to create a seperate class that extends the BroadcastReceiver class, this cannot be inherreted.

Categories

Resources