Brand new to android development and I wanted to test some new code that I was working on. So I launched the my app on the emulator and the splash screen loads fine.However after the 5 second timer finishes the app crashes.
This is my Manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.PackageName.alarmclock"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.SET_WALLPAPER" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<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=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.PackageName.AlarmClock.MENU" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Menu"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.PackageName.AlarmClock.ASDF" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".TextPlay"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.PackageName.AlarmClock.TextPlay" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Email"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.PackageName.AlarmClock.Email" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Camera"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.PackageName.AlarmClock.Camera" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Here is my splash.java
OnCreate is dashed out in eclipse and I don't know why and if that is the reason for the crashing
package com.PackageName.alarmclock;
import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
public class Splash extends Activity{
MediaPlayer ourSong;
#Override
#Deprecated
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
ourSong = MediaPlayer.create(Splash.this, R.raw.splashsound);
ourSong.start();
Thread timer = new Thread(){
public void run(){
try{
sleep(5000);
} catch (InterruptedException e){
e.printStackTrace();
}finally{
Intent openMainActivity = new Intent("com.PackageName.AlarmClock.MENU");
startActivity(openMainActivity);
}
}
};
timer.start();
}
#Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
ourSong.release();
finish();
}
}
And if you need it, here is the Menu.Java
package com.PackageName.alarmclock;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class Menu extends ListActivity{
String classes[] = { "MainActivity", "TextPlay", "Splash", "Email", "Camera", "example5", "example6"};
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(Menu.this, android.R.layout.simple_list_item_1, classes));
}
#Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
String cheese= classes[position];
try{
Class<?> ourClass = Class.forName("com.PackageName.AlarmClock." + cheese);
Intent ourIntent = new Intent(Menu.this, ourClass);
startActivity(ourIntent);
}catch(ClassNotFoundException e){
e.printStackTrace();
}
}
}
And here is the LogCat
07-16 00:48:16.120: E/AndroidRuntime(1985): FATAL EXCEPTION: Thread-84
07-16 00:48:16.120: E/AndroidRuntime(1985): Process: com.PackageName.alarmclock, PID: 1985
07-16 00:48:16.120: E/AndroidRuntime(1985): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.PackageName.AlarmClock.MENU }
07-16 00:48:16.120: E/AndroidRuntime(1985): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1632)
07-16 00:48:16.120: E/AndroidRuntime(1985): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1424)
07-16 00:48:16.120: E/AndroidRuntime(1985): at android.app.Activity.startActivityForResult(Activity.java:3424)
07-16 00:48:16.120: E/AndroidRuntime(1985): at android.app.Activity.startActivityForResult(Activity.java:3385)
07-16 00:48:16.120: E/AndroidRuntime(1985): at android.app.Activity.startActivity(Activity.java:3627)
07-16 00:48:16.120: E/AndroidRuntime(1985): at android.app.Activity.startActivity(Activity.java:3595)
07-16 00:48:16.120: E/AndroidRuntime(1985): at com.PackageName.alarmclock.Splash$1.run(Splash.java:28)
Any help is appreciated as I've spent pretty much the whole day on this app and It'd suck to lose it.
Add this to your manifest:
<activity
android:name=".Menu"
android:label="#string/app_name" >
</activity>
Call it in Intent as :
Intent openMainActivity = new Intent(Splash.this, Menu.class);
Right now what you have in your manifest is:
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
which, from the code that you have pasted, doesn't exist.
Leave alone, the ListActivity in java file has the name "Menu" and what you declared in manifest is "MENU"
Try this
Intent openMainActivity = new Intent(getApplicationContext(), Menu.class);
You have to use intents something like this
Intent i=new Intent(Firstactivity.this,SecondActivity.class);
startActivity(i);
Where first activity is your current activity and second activity is the one you want to move on to; but in your finally block you are doing something like
Intent openMainActivity = new Intent("com.PackageName.AlarmClock.MENU");//wrong
//you specified only one argument
startActivity(openMainActivity);
which is wrong
Change this line in Splash.java file
Intent openMainActivity = new Intent("com.PackageName.AlarmClock.MENU");
to
Intent openMainActivity = new Intent();
openMainActivity.setClass(this, Menu.class);
And
in Menu.java file change from
Class<?> ourClass = Class.forName("com.PackageName.AlarmClock." + cheese);
Intent ourIntent = new Intent(Menu.this, ourClass);
startActivity(ourIntent);
to
Intent ourIntent = new Intent();
ourIntent.setClass(this, AlarmClock.class);
startActivity(ourIntent);
Related
i have a application that allows me to alter/add/delete from mysql database. The application opens up fine when i run it but when i try clicking on the 'ViewAllEmployee' button i keep getting a error saying it cannot find explicit activity class. I have looked online and tried all solutions that have worked for people with this problem before. I have added it into my AndroidManifest too but it still doesn't want to work. Can anyone help? Literally been trying to fix this for hours!
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.assignment.androidassignment"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-sdk
android:minSdkVersion="18"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:label="#string/app_name" >
<activity
android:name="com.example.assignment.androidassignment.MainActivity"
android:label="#string/app_name"
android:theme="#android:style/Theme.Holo.Dialog" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<activity
android:name="com.example.assignment.androidassignment.ViewAllEmployee"
/>
</activity>
</application>
</manifest>
MainActivity.java -- Error showing when onClick for 'ViewAllEmployee' is clicked:
package com.example.assignment.androidassignment;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import java.util.HashMap;
public class MainActivity extends Activity implements View.OnClickListener{
//Defining views
private EditText editTextLatitude;
private EditText editTextLongitude;
private EditText editTextTimeInserted;
private Button buttonAdd;
private Button buttonView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Initializing views
editTextLatitude = (EditText) findViewById(R.id.editTextLat);
editTextLongitude = (EditText) findViewById(R.id.editTextLon);
editTextTimeInserted = (EditText) findViewById(R.id.editTextTimeInserted);
buttonAdd = (Button) findViewById(R.id.buttonAdd);
buttonView = (Button) findViewById(R.id.buttonView);
//Setting listeners to button
buttonAdd.setOnClickListener(this);
buttonView.setOnClickListener(this);
}
//Adding an employee
private void addEmployee(){
final String lat = editTextLatitude.getText().toString().trim();
final String lon = editTextLongitude.getText().toString().trim();
final String timeInserted = editTextTimeInserted.getText().toString().trim();
class AddEmployee extends AsyncTask<Void,Void,String>{
ProgressDialog loading;
#Override
protected void onPreExecute() {
super.onPreExecute();
loading = ProgressDialog.show(MainActivity.this,"Adding...","Wait...",false,false);
}
#Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
loading.dismiss();
Toast.makeText(MainActivity.this,s,Toast.LENGTH_LONG).show();
}
#Override
protected String doInBackground(Void... v) {
HashMap<String,String> params = new HashMap<>();
params.put(Config.KEY_LAT,lat);
params.put(Config.KEY_LON,lon);
params.put(Config.KEY_TIMEINSERTED,timeInserted);
RequestHandler rh = new RequestHandler();
String res = rh.sendPostRequest(Config.URL_ADD, params);
return res;
}
}
AddEmployee ae = new AddEmployee();
ae.execute();
}
#Override
public void onClick(View v) {
if(v == buttonAdd){
addEmployee();
}
if(v == buttonView){
startActivity(new Intent(this,com.example.assignment.androidassignment.ViewAllEmployee.class));
}
}
}
LogCat errors:
12-09 03:34:46.634 2489-2489/? E/AndroidRuntime: FATAL EXCEPTION: main
=Process: com.example.assignment.androidassignment, PID: 2489
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.assignment.androidassignment/com.example.assignment.androidassignment.ViewAllEmployee}; have you declared this activity in your AndroidManifest.xml?
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1628)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1424)
at android.app.Activity.startActivityForResult(Activity.java:3424)
at android.app.Activity.startActivityForResult(Activity.java:3385)
at android.app.Activity.startActivity(Activity.java:3627)
at android.app.Activity.startActivity(Activity.java:3595)
at com.example.assignment.androidassignment.MainActivity.onClick(MainActivity.java:91)
at android.view.View.performClick(View.java:4438)
at android.view.View$PerformClick.run(View.java:18422)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
You are nesting <activity> tags in your Manifest. Take them apart:
<activity
android:name="com.example.assignment.androidassignment.MainActivity"
android:label="#string/app_name"
android:theme="#android:style/Theme.Holo.Dialog" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.assignment.androidassignment.ViewAllEmployee"/>
from
if(v == buttonView){
startActivity(new Intent(this,com.example.assignment.androidassignment.ViewAllEmployee.class));
}
to
if(v == buttonView){
startActivity(new Intent(MainActivity.this,ViewAllEmployee.class));
}
from
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.assignment.androidassignment"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-sdk
android:minSdkVersion="18"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:label="#string/app_name" >
<activity
android:name="com.example.assignment.androidassignment.MainActivity"
android:label="#string/app_name"
android:theme="#android:style/Theme.Holo.Dialog" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<activity
android:name="com.example.assignment.androidassignment.ViewAllEmployee"
/>
</activity>
</application>
</manifest>
to
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.assignment.androidassignment"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-sdk
android:minSdkVersion="18"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:label="#string/app_name" >
<activity
android:name="com.example.assignment.androidassignment.MainActivity"
android:label="#string/app_name"
android:theme="#android:style/Theme.Holo.Dialog" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.assignment.androidassignment.ViewAllEmployee"
/>
</application>
</manifest>
please change the above and this is happening because of nesting of activity inside manifest
I am learning the basics of android programming. Now I have made a Life Cycle test. The list activity works fine, but when I attempt to open the Life Cycle test, the app stops and closes. I have got the same problem on several devices. These are my codes:
(Manifest)
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.badlogic.androidgames"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".AndroidBasicsStarter"
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>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
</manifest>
(AndroidBasicsStarter.java)
package com.badlogic.androidgames;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class AndroidBasicsStarter extends ListActivity {
String tests[] = { "LifeCycleTest", "SingleTouchTest", "MultiTouchTest", "KeyTest",
"AccelerometerTest", "AssetsTest", "ExternalStorageTest", "SoundPoolTest",
"MediaPlayerTest", "FullScreenTest", "RenderViewTest", "ShapeTest", "BitmapTest",
"FontTest", "SurfaceViewTest"
};
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, tests));
}
#Override
protected void onListItemClick(ListView list, View view, int position, long id) {
super.onListItemClick(list, view, position, id);
String testName = tests[position];
try {
Class clazz = Class
.forName("com.badlogic.androidgames." + testName);
Intent intent = new Intent(this, clazz);
startActivity(intent);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}
(LifeCycleTest.java)
package com.badlogic.androidgames;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
public class LifeCycleTest extends Activity {
StringBuilder builder = new StringBuilder();
TextView textView;
private void log(String text) {
Log.d("LifeCycleTest", text);
builder.append(text);
builder.append('\n');
textView.setText(builder.toString());
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
textView = new TextView(this);
textView.setText(builder.toString());
setContentView(textView);
log("created");
}
#Override
protected void onResume() {
super.onResume();
log("resumed");
}
#Override
protected void onPause() {
super.onPause();
log("paused");
if (isFinishing()) {
log("finishing");
}
}
}
I use Eclipse on Windows 7. Thank you in advance!
Add your LifeCycleTest activity in AndroidManifest.xml
<activity
android:name=".LifeCycleTest"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
Include both your activities inside your Manifest file. It should look something like this.
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".AndroidBasicsStarter"
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=".LifeCycleTest"
android:label="#string/app_name" >
</activity>
</application>
I'm a beginner android developer here and I coded a basic activity that loads an image, waits for 5 seconds and opens the main activity that holds a text view. There are no errors and it compiles perfectly fine. When I launch on my device though, it doesn't open. (Doesn't open on the emulator either).
I'm not sure why this is.
Here is the manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.gui"
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"
android:debuggable="true">
<activity
android:name="com.example.gui.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.example.gui.Splash"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.SPLASH" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Here is the Splash activity I intent to load first.
package com.example.gui;
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 splash_thread = new Thread(){
public void run(){
try{
sleep(5000);
} catch(InterruptedException e)
{ e.printStackTrace();
}finally{ Intent splash_intent = new Intent("android.intent.action.MAIN");
startActivity(splash_intent);
}
}
};
splash_thread.start();
}
#Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
finish();
}
}
And here is the other activity I intend to run:
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
I'm following a tutorial off the internet, this still doesn't run for some reason. My layout's are very standard as well. Help'd be appreciated.
You can set wrong path in manifest.xml file.
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
android:debuggable="true">
<activity
android:name="com.example.gui.Splash"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.example.gui.MainActivity"
android:label="#string/app_name" >
try this and now your splash screen lauch first and the main activity will launch...
if it not working then try this code only if your activity will not give response.
public class Splash_screen extends Activity {
private static String TAG = Splash_screen.class.getName();
private static long SLEEP_TIME = 3; // Sleep for some time
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
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.splash_screen);
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(Splash_screen.this,Login_screen.class);
startActivity(intent);
finish();
}
}
So I am trying to run this app I am using to learn about threads and intents however the app will not run, But I don't have any warning/error underlines in the code, could anyone help me please.
Manifest code:
<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.learn.tam.Splash"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.SPLASH" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.learn.tam.StartingPoint"
android:label="#string/app_name" >
</activity>
</application>
</manifest>
and Activity code
package com.example.learn.tam;
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.example.learn.tam.StartingPoint");
startActivity(openStartingPoint);
}
}
};
timer.start();
}
}
any help would be appreciated please
Change
<intent-filter>
<action android:name="android.intent.action.SPLASH" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
to
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
Since your app is probably not shown on the home screen (the MAIN category is needed).
And also change
Intent openStartingPoint = new Intent("com.example.learn.tam.StartingPoint");
startActivity(openStartingPoint);
to
Intent openStartingPoint = new Intent(Splash.this, StartingPoint.class );
startActivity(openStartingPoint);
Since your StartingPoint does not define an Intent-Action with "com.example.learn.tam.StartingPoint"
See if that fixes anything.
Remove this:
<action android:name="android.intent.action.SPLASH" />
And replace it with this:
<action android:name="android.intent.action.MAIN" />
I want my application to be automatically launched when the system is started. Can anyone tell me how to do that?
Thanks in advance for the time you will spend trying to help me.
First, you need the permission in your manifest:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
Also, in your manifest, define your service and listen for the boot-completed action:
<service android:name=".MyService" android:label="My Service">
<intent-filter>
<action android:name="com.myapp.MyService" />
</intent-filter>
</service>
<receiver
android:name=".receiver.StartMyServiceAtBootReceiver"
android:enabled="true"
android:exported="true"
android:label="StartMyServiceAtBootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
Then you need to define the receiver that will get the BOOT_COMPLETED action and start your service.
public class StartMyServiceAtBootReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
if ("android.intent.action.BOOT_COMPLETED".equals(intent.getAction())) {
Intent serviceIntent = new Intent("com.myapp.MySystemService");
context.startService(serviceIntent);
}
}
}
And now your service should be running when the phone starts up.
Here is Complete working Example Code,
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.practice" android:versionCode="1" android:versionName="1.0">
<uses-sdk android:minSdkVersion="4" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"></uses-permission>
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".AutoStartExampleActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name="AutoStart"></receiver>
<receiver android:name=".AutoStart">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
</application>
</manifest>
AutoStartExampleActivity File
package com.practice;
import android.app.Activity;
import android.os.Bundle;
public class AutoStartExampleActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
BroadcastReceiver Code,
package com.practice;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class AutoStart extends BroadcastReceiver
{
public void onReceive(Context context, Intent intent)
{
System.out.println ( "Application Started" );
// put your TimerTask calling class here
try
{
Intent myIntent = new Intent ( context, AutoStartExampleActivity.class );
myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(myIntent);
}
catch ( Exception e )
{
System.out.println ( " Error while Starting Activity " + e.toString() );
}
}
}