Cannot start search activity when searching for data android - android

So I am trying to program this search activity and when I execute the search in my emulator, I am getting an error in my log cat that says the activity cant be started and I can't figure out what is causing that error.
Search activity code:
package com.example.myfirstapp;
import android.os.Bundle;
import android.app.SearchManager;
import android.app.ListActivity;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.content.Intent;
import android.database.Cursor;
public class SearchResultsActivity extends ListActivity {
private ListView list;
DatabaseTable db = new DatabaseTable(this);
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(android.R.id.list);
handleIntent(getIntent());
}
public void onNewIntent(Intent intent) {
setIntent(intent);
handleIntent(intent);
}
private void handleIntent(Intent intent) {
if (Intent.ACTION_VIEW.equals(intent.getAction())) {
Intent contactIntent = new Intent(this, ContactActivity.class);
contactIntent.setData(intent.getData());
startActivity(contactIntent);
finish();
} else if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
String query = intent.getStringExtra(SearchManager.QUERY);
showResults(query);
}
}
private void showResults(String query) {
int name = 0;
String c = "";
Cursor cursor = db.getContactMatches(query, null);
int cursor_length = db.cursorLength(cursor);
String[] display = new String[cursor_length];
list = (ListView)findViewById(android.R.id.list);
int x = 0;
//Loading data through Cursor into String array
for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext())
{
name = cursor.getColumnIndex(DatabaseTable.COL_NAME);
c = (cursor.getString(name));
display[x] = c;
c = "";
x = x + 1;
name = 0;
}
ArrayAdapter<String> contactAdapter = new ArrayAdapter<String>(this,
R.layout.activity_search_results, android.R.id.list, display);
list.setAdapter(contactAdapter);
list.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent contactIntent = new Intent(getApplicationContext(),ContactActivity.class);
contactIntent.setData(getIntent().getData());
startActivity(contactIntent);
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_search_results, menu);
return true;
}
}
Android Manifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myfirstapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="15" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data
android:name="android.app.default_searchable"
android:value=".SearchResultsActivity" />
</activity>
<activity
android:name=".SearchResultsActivity"
android:label="#string/title_activity_search_results"
android:launchMode="singleTop" >
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
</intent-filter>
<meta-data
android:name="android.app.searchable"
android:resource="#xml/searchable" />
</activity>
<activity
android:name=".AddContacts"
android:label="#string/title_activity_add_contacts" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ContactActivity"
android:label="#string/title_activity_contact" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

here
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(android.R.id.list); //<<<<
you are adding ListView id as contentview of ListActivity . just remove setContentView(android.R.id.list); from onCreate of ListActivity and add your own layout for Activty
and move database instance initulization inside onCreate method as
DatabaseTable db;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main); // <<< add activity layout here
db = new DatabaseTable(this);
see this tutorial for creating an layout with ListView :
http://www.java2s.com/Code/Android/UI/UsingImageViewwithinListActivity.htm

Related

onClickListener crashes program wont link to another activity android

My Main Activity class is as follows
package com.example.barnight2;
import java.text.SimpleDateFormat;
import java.util.Date;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity {
private TextView date;
private Button taxiButton;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addListenerOnButton();
dateAndTime();
}
public void addListenerOnButton() {
taxiButton = (Button) findViewById(R.id.btnTaxi);
taxiButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent taxiIntent = new Intent(MainActivity.this, TaxiActivity.class);
startActivity(taxiIntent);
}
});
}
public void dateAndTime() {
date = (TextView) findViewById(R.id.lblDate);
SimpleDateFormat sdf = new SimpleDateFormat("EEEE");
Date day = new Date();
String dayOfTheWeek = sdf.format(day);
date.setText(dayOfTheWeek);
}
}
then i have my second activity called the Taxi Activity
package com.example.barnight2;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class TaxiActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_taxi);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.taxi, menu);
return true;
}
}
Here is my Manifest.xml i thought i had done everything perfectly but it seems to always crash upon start up of the app
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.barnight2"
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.barnight2.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.example.barnight2.TaxiActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
</application>
</manifest>
![image]http://i62.tinypic.com/16rma8.png
ClassCastException
you're casting an object that it's not the same type you're trying to cast, so that's why it throw a RunTimeException with ClassCastException.
It should be:
taxiButton = (ImageButton) findViewById(R.id.btnTaxi);
Since you declared it as ImageButton in xml.
Please remove :
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
from your activity com.example.barnight2.TaxiActivity in the AndroidManifest.xml

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

Activity not launching correctly although described in Manifest

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.app.android"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="15" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.StyledCustom" >
<activity
android:name=".SplashActivity"
android:label="#string/title_activity_main"
>
<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/title_activity_main"
android:theme="#style/Theme.StyledCustom" >
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
I'm including the SplashActivity.java (I am using ActionBarSherlock):
package com.app.android;
import com.app.android.R;
import android.content.Intent;
import android.os.Bundle;
import com.actionbarsherlock.app.SherlockActivity;
public class SplashActivity extends SherlockActivity{
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
getSupportActionBar().hide();
Thread timerSplash = new Thread(){
#Override
public void run() {
try{
int i = 0;
while(i < 1000){
i+=100;
sleep(100);
}
startActivity(new Intent("com.app.android.MainActivity"));
}catch(Exception ex){
}finally{
finish();
}
}
};
timerSplash.start();
}
}
What I am facing is that my MainActivity is getting Launched before SplashActivity.
Also a warning is generated at MainActivity activity node in AndroidManifest.xml : "Exported activity does not require permission"
Can any one say what is happening?
In Manifast.xml:
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main"
android:theme="#style/Theme.StyledCustom" >
</activity>
And Class as Below
public class SplashActivity extends SherlockActivity{
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
getSupportActionBar().hide();
Thread timerSplash = new Thread(){
#Override
public void run() {
try{
int i = 0;
while(i < 1000){
i+=100;
sleep(100);
}
Intent intent = new Intent(SplashActivity.this, MainActivity.class);
startActivity(intent);
}catch(Exception ex){
}finally{
finish();
}
}
};
timerSplash.start();
}
}
define Activity as in Manifast.xml:
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main"
android:theme="#style/Theme.StyledCustom" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
and start as:
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.app.android", "com.app.android.MainActivity"));
startActivity(intent);

Categories

Resources