I can't start my application with Android Splash Screen - android

I'm trying to add splash screen activity to my android application, I'm doing everything what I saw on lessons on the internet but it doesn't work. It always say "unfortunately, * has stopped." What can be the reason?
Thanks..
my main activity
<code>package com.fckirbay.istatistikelkitap;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class MainActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.acilis);
Thread thread = new Thread() {
#Override
public void run() {
try {
synchronized (this) {
wait(4000);
}
} catch (InterruptedException e) {
// Hata yönetimi
} finally {
finish();
// Yeni açılmak istenen Intent
Intent intent = new Intent();
intent.setClass(getApplicationContext(), acilis.class);
startActivity(intent);
}
}
};
// Thread başlatılıyor
thread.start();
}
}</code>
mysplash screen
package com.fckirbay.istatistikelkitap;
import com.fckirbay.istatistikelkitap.R;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
public class acilis extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button tablolar=(Button)findViewById(R.id.tablolar);
Button istatistikciler=(Button)findViewById(R.id.istatistikciler);
Button unite1=(Button)findViewById(R.id.unite1);
Button unite2=(Button)findViewById(R.id.unite2);
Button unite3=(Button)findViewById(R.id.unite3);
Button unite4=(Button)findViewById(R.id.unite4);
Button unite5=(Button)findViewById(R.id.unite5);
Button unite6=(Button)findViewById(R.id.unite6);
Button devam=(Button)findViewById(R.id.devam);
devam.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent("com.fckirbay.istatistikelkitap.EKRANIKI"));
}
});
tablolar.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent("com.fckirbay.istatistikelkitap.TABLOLAR"));
}
});
istatistikciler.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent("com.fckirbay.istatistikelkitap.ISTATISTIKCILER"));
}
});
unite1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent("com.fckirbay.istatistikelkitap.UNITE1"));
}
});
unite2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent("com.fckirbay.istatistikelkitap.UNITE2"));
}
});
unite3.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent("com.fckirbay.istatistikelkitap.UNITE3"));
}
});
unite4.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent("com.fckirbay.istatistikelkitap.UNITE4"));
}
});
unite5.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent("com.fckirbay.istatistikelkitap.UNITE5"));
}
});
unite6.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent("com.fckirbay.istatistikelkitap.UNITE6"));
}
});
}
#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;
}
}
and activity manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.fckirbay.istatistikelkitap"
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.fckirbay.istatistikelkitap.MainActivity"
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.fckirbay.istatistikelkitap.acilis"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.ACILIS" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

in your manifest file the application entry point should be MainActivity.
should have something that looks like this in your manifest file.
<activity
android:name="com.example.MainActivity"
android:label="#string/app_name" android:screenOrientation="landscape" android:configChanges="keyboard|keyboardHidden|orientation" android:theme="#android:style/Theme.NoTitleBar.Fullscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
ok try this:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.fckirbay.istatistikelkitap"
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.fckirbay.istatistikelkitap.MainActivity"
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="Acilis" />
</activity>
</application>
</manifest>

Problem is you have defined two launcher activities. Make your Splash activity your LAUNCHER and your MainActivity DEFAULT.
For your Splash Activity:
<category android:name="android.intent.category.LAUNCHER"
For your Main Activity:
<category android:name="android.intent.category.DEFAULT"

Related

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>

problems passing parameter from one java class to another (android)

Hi I have trouble in passing parameter from one java class to another in android using intent. from Main Menu to Chinese Page
MainMenu:
package com.example.myfirstapp;
import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainMenu extends Activity {
public MediaPlayer mpSplash;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.mainmenu);
//final MediaPlayer mpSplash = MediaPlayer.create(this, R.raw.kalimba);
//mpSplash.start();
//set up button sound
final MediaPlayer mpButtonClick = MediaPlayer.create(this, R.raw.button_sound);
//WESTERN PAGE
Button bWestern = (Button) findViewById(R.id.western);
bWestern.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent("com.example.myfirstapp.WESTERNPAGE"));
mpButtonClick.start();
}
});
//CHINESE PAGE
Button bChinese = (Button) findViewById(R.id.chinese);
bChinese.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent ("com.example.myfirstapp.CHINESEPAGE");
intent.putExtra("STRING_PASS", "this is a value passed from mainmenu class");
startActivity(intent);
mpButtonClick.start();
}
});
//JAPANESE PAGE
Button bJapanese = (Button) findViewById(R.id.japanese);
bJapanese.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent("com.example.myfirstapp.JAPANESEPAGE"));
mpButtonClick.start();
}
});
//ORIENTAL PAGE
Button bOriental = (Button) findViewById(R.id.oriental);
bOriental.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent("com.example.myfirstapp.ORIENTALPAGE"));
mpButtonClick.start();
}
});
//FAVOURITES PAGE
Button bFavourites = (Button) findViewById(R.id.favourites);
bFavourites.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent("com.example.myfirstapp.FAVOURITESPAGE"));
mpButtonClick.start();
}
});
//OtherS PAGE
Button bOthers = (Button) findViewById(R.id.others);
bOthers.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent("com.example.myfirstapp.OTHERSPAGE"));
mpButtonClick.start();
}
});
}
}
to Chinese Page:
package com.example.myfirstapp;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
public class ChinesePage extends Activity{
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
Intent intent = getIntent();
String s = intent.getExtras().getString("STRING_PASS");
TextView description = (TextView) findViewById(R.id.description);
description.setText(s);
super.onCreate(savedInstanceState);
setContentView(R.layout.chinesepage);
}
}
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myfirstapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher_cook"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar">
<activity
android:name="com.example.myfirstapp.SplashScreen"
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.myfirstapp.MainMenu"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.example.myfirstapp.CLEARSCREEN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.example.myfirstapp.WesternPage"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.example.myfirstapp.WESTERNPAGE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.example.myfirstapp.ChinesePage"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.example.myfirstapp.CHINESEPAGE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.example.myfirstapp.JapanesePage"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.example.myfirstapp.JAPANESEPAGE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.example.myfirstapp.OrientalPage"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.example.myfirstapp.ORIENTALPAGE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.example.myfirstapp.FavouritesPage"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.example.myfirstapp.FAVOURITESPAGE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.example.myfirstapp.OthersPage"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.example.myfirstapp.OTHERSPAGE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
My layout is as follows:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/description"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"/>
</LinearLayout>
I have been getting a 'unfortunately. application has stopped' when i click the chinese page button.
is there something that I'm missing here :\
Thanks in advance
You need to set the content of the layout to the activity first and then initialize views.
I guess you have a NUllPointerException. Also make sure you have ChinesePage activity declared in manifest.
Intent intent = new Intent(MainMenu.this,Chinsepage.class)
intent.putExtra("STRING_PASS", "this is a value passed from mainmenu class");
startActivity(intent);
// similarly for others
And in manifest
<activity
android:name=".ChinesePage"
android:label="#string/app_name">
</activity>
// similar for other activities
And do read about explicit and implicit intents #
http://developer.android.com/guide/components/intents-filters.html
So in ChinesePage change as below
super.onCreate(savedInstanceState);
setContentView(R.layout.chinesepage); // first
TextView description = (TextView) findViewById(R.id.description);
Intent intent = getIntent();
String s = intent.getExtras().getString("STRING_PASS");
description.setText(s);

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;
}
}

Using Intent in an Android application to show another activity

In my Android application, I have two activity classes. I have a button on the first one and I want to show the second when it is clicked, but I get an error. Here are the classes:
public class FirstActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button orderButton = (Button)findViewById(R.id.order);
orderButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(FirstActivity.this, OrderScreen.class);
startActivity(intent);
}
});
}
}
The second class that should show when the button is clicked, but never does:
public class OrderScreen extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.order);
Button orderButton = (Button) findViewById(R.id.end);
orderButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
finish();
}
});
}
}
How do I create a button that will show the second activity?
The issue was the OrderScreen Activity wasn't added to the AndroidManifest.xml. Once I added that as an application node, it worked properly.
<activity android:name=".OrderScreen" />
Add this line to your AndroidManifest.xml:
<activity android:name=".OrderScreen" />
----FirstActivity.java-----
package com.mindscripts.eid;
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 {
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button orderButton = (Button) findViewById(R.id.order);
orderButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(FirstActivity.this,OrderScreen.class);
startActivity(intent);
}
});
}
}
---OrderScreen.java---
package com.mindscripts.eid;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class OrderScreen extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.second_class);
Button orderButton = (Button) findViewById(R.id.end);
orderButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
finish();
}
});
}
}
---AndroidManifest.xml----
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mindscripts.eid"
android:versionCode="1"
android:versionName="1.0">
<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=".OrderScreen"></activity>
</application>
Use this code:
Intent intent=new Intent(context,SecondActivty.class);
startActivity(intent);
finish();
context: refer to current activity context,
please make sure that you have added activity in android manifest file.
Following code for adding activity in android manifest file
<Activity name=".SecondActivity">
</Activity>
<activity android:name="[packagename optional].ActivityClassName"></activity>
Simply adding the activity which we want to switch to should be placed in the manifest file
When you create any activity in android file you have to specify it in AndroidManifest.xml like
<uses-sdk android:minSdkVersion="8" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".MyCreativityActivity"
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=".OrderScreen"></activity>
</application>
b1 = (Button) findViewById(R.id.click_me);
b1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent i = new Intent(MainActivity.this, SecondActivity.class);
startActivity(i);
}
});
add the activity in your manifest file
<activity android:name=".OrderScreen" />
In the Manifest
<activity android:name=".OrderScreen" />
In the Java Code where you have to place intent code
startActivity(new Intent(CurrentActivity.this, OrderScreen.class);
you can use the context of the view that did the calling.
Example:
Button orderButton = (Button)findViewById(R.id.order);
orderButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(/*FirstActivity.this*/ view.getContext(), OrderScreen.class);
startActivity(intent);
}
});
Intent i = new Intent("com.Android.SubActivity");
startActivity(i);

Categories

Resources