I am trying to start an Activity from another activity with an ACTION_MAIN.
I am doing this because I want to give to other apps the possibility to start this secondary activity as well. So in my manifest I have two MAIN activities:
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="main.package"
android:versionCode="34"
android:versionName="3.04"
android:installLocation="preferExternal"
>
....
<activity
android:name=".SplashActivity"
android:label="#string/app_name"
android:icon="#drawable/myicon"
>
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="main.package.secondary.SecondaryActivity"
android:label="#string/memorapp"
android:theme="#style/Theme.Sherlock.Light"
android:taskAffinity="main.package.secondary.SecondaryActivity"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
In my main activity I run the following code:
Intent intent = new Intent(Intent.ACTION_MAIN);
ComponentName cn = new ComponentName("main.package.secondary","main.package.secondary.SecondaryActivity");
intent.setComponent(cn);
startActivity(intent);
and here is the logcat:
03-28 16:35:41.987: E/AndroidRuntime(9921): FATAL EXCEPTION: main
03-28 16:35:41.987: E/AndroidRuntime(9921): android.content.ActivityNotFoundException: Unable to find explicit activity class {main.package.secondary/main.package.secondary.secondaryMainActivity}; have you declared this activity in your AndroidManifest.xml?
03-28 16:35:41.987: E/AndroidRuntime(9921): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1405)
03-28 16:35:41.987: E/AndroidRuntime(9921): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379)
03-28 16:35:41.987: E/AndroidRuntime(9921): at android.app.Activity.startActivityForResult(Activity.java:2827)
03-28 16:35:41.987: E/AndroidRuntime(9921): at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:674)
03-28 16:35:41.987: E/AndroidRuntime(9921): at android.app.Activity.startActivity(Activity.java:2933)
03-28 16:35:41.987: E/AndroidRuntime(9921): at main.package.MainActivity.onMenufrag(MainActivity.java:206)
03-28 16:35:41.987: E/AndroidRuntime(9921): at main.package.MenuFragment.sendBodyTextToActivity(MenuFragment.java:92)
03-28 16:35:41.987: E/AndroidRuntime(9921): at main.package.MenuFragment.access$0(MenuFragment.java:90)
03-28 16:35:41.987: E/AndroidRuntime(9921): at main.package.MenuFragment$1.onClick(MenuFragment.java:66)
03-28 16:35:41.987: E/AndroidRuntime(9921): at android.view.View.performClick(View.java:2501)
03-28 16:35:41.987: E/AndroidRuntime(9921): at android.view.View$PerformClick.run(View.java:9107)
03-28 16:35:41.987: E/AndroidRuntime(9921): at android.os.Handler.handleCallback(Handler.java:587)
03-28 16:35:41.987: E/AndroidRuntime(9921): at android.os.Handler.dispatchMessage(Handler.java:92)
03-28 16:35:41.987: E/AndroidRuntime(9921): at android.os.Looper.loop(Looper.java:130)
03-28 16:35:41.987: E/AndroidRuntime(9921): at android.app.ActivityThread.main(ActivityThread.java:3835)
03-28 16:35:41.987: E/AndroidRuntime(9921): at java.lang.reflect.Method.invokeNative(Native Method)
03-28 16:35:41.987: E/AndroidRuntime(9921): at java.lang.reflect.Method.invoke(Method.java:507)
03-28 16:35:41.987: E/AndroidRuntime(9921): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:847)
03-28 16:35:41.987: E/AndroidRuntime(9921): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
03-28 16:35:41.987: E/AndroidRuntime(9921): at dalvik.system.NativeStart.main(Native Method)
Could you tell me why my Activity is not found or what should I do so that my SecondaryActivity is started
Could you try this?
Intent intent = new Intent(Intent.ACTION_MAIN);
ComponentName cn = new ComponentName("main.package","main.package.secondary.SecondaryActivity");
intent.setComponent(cn);
startActivity(intent);
First paramater takes "Application package name"
Try setting the following intent-filters to your second activity:
<intent-filter>
<action android:name="main.package.secondary.SecondaryActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
Put in manifest.xml:
<activity android:name="main.package.secondary.SecondaryActivity" android:label="#string/memorapp" android:theme="#style/Theme.Sherlock.Light" android:taskAffinity="main.package.secondary.SecondaryActivity"> </activity>
without intent-filter atributes.
Related
Presently, I am working on app that sets the phone into the vibration mode or the ringer mode at the selected time. I have successfully implemented this using the alarmmanager in my application.
I want my app to remember all the pending intents when the phone is rebooted.
I found a sample code in the internet, but it seems to crash my app when the phone is rebooted. I don't know what's going wrong.
Here is alarmreciever.java
package ishan.khandelwal.vitsilentmode;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.media.AudioManager;
import android.widget.Toast;
public class AlarmReciever extends BroadcastReceiver
{
private AudioManager mAudioManager;
#Override
public void onReceive(Context context, Intent intent)
{
// TODO Auto-generated method stub
if ("android.intent.action.BOOT_COMPLETED".equals(intent.getAction())) {
Intent serviceIntent = new Intent("ishan.khandelwal.vitsilentmode");
context.startService(serviceIntent);
}
mAudioManager = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
mAudioManager.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
// Show the toast
Toast.makeText(context, "Vibration Mode", Toast.LENGTH_SHORT).show();
}
}
Android manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ishan.khandelwal.vitsilentmode"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<!-- permission required to use Alarm Manager -->
<uses-permission android:name="com.android.alarm.permission.SET_ALARM"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<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>
<activity
android:name="ishan.khandelwal.vitsilentmode.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="ishan.khandelwal.vitsilentmode.GetSlots"
android:label="Select your slots"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="ishan.khandelwal.vitsilentmode.MorningSlots"
android:label="Select your morning slots"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="ishan.khandelwal.vitsilentmode.EveningSlots"
android:label="Select your evening slots"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="ishan.khandelwal.vitsilentmode.Labs"
android:label="Select your lab slots"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="ishan.khandelwal.vitsilentmode.About"
android:label="About"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="ishan.khandelwal.vitsilentmode.AlarmReciever"
android:label="AlarmReciever" >
</activity>
<!-- Register the Alarm Receiver -->
<receiver android:name=".AlarmReciever"/>
<activity
android:name="ishan.khandelwal.vitsilentmode.RingerMode"
android:label="RingerMode" >
</activity>
<!-- Register the Alarm Receiver -->
<receiver android:name=".RingerMode"/>
</application>
Logcat:
07-23 23:33:12.057: I/ActivityManager(858): Start proc com.android.providers.calendar for broadcast com.android.providers.calendar/.CalendarReceiver: pid=1116 uid=10023 gids={3003}
07-23 23:33:12.067: I/ActivityThread(1116): Pub com.android.calendar: com.android.providers.calendar.CalendarProvider2
07-23 23:33:12.087: I/SurfaceFlinger(858): Boot is finished (2041 ms)
07-23 23:33:12.128: I/ActivityManager(858): Start proc ishan.khandelwal.vitsilentmode for broadcast ishan.khandelwal.vitsilentmode/.receiver.StartMyServiceAtBootReceiver: pid=1127 uid=10031 gids={}
07-23 23:33:12.137: D/AndroidRuntime(1127): Shutting down VM
07-23 23:33:12.137: W/dalvikvm(1127): threadid=1: thread exiting with uncaught exception (group=0xb6fac4f0)
07-23 23:33:12.137: E/AndroidRuntime(1127): FATAL EXCEPTION: main
07-23 23:33:12.137: E/AndroidRuntime(1127): java.lang.RuntimeException: Unable to instantiate receiver ishan.khandelwal.vitsilentmode.receiver.StartMyServiceAtBootReceiver: java.lang.ClassNotFoundException: ishan.khandelwal.vitsilentmode.receiver.StartMyServiceAtBootReceiver in loader dalvik.system.PathClassLoader[/data/app/ishan.khandelwal.vitsilentmode-1.apk]
07-23 23:33:12.137: E/AndroidRuntime(1127): at android.app.ActivityThread.handleReceiver(ActivityThread.java:1773)
07-23 23:33:12.137: E/AndroidRuntime(1127): at android.app.ActivityThread.access$2400(ActivityThread.java:117)
07-23 23:33:12.137: E/AndroidRuntime(1127): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:981)
07-23 23:33:12.137: E/AndroidRuntime(1127): at android.os.Handler.dispatchMessage(Handler.java:99)
07-23 23:33:12.137: E/AndroidRuntime(1127): at android.os.Looper.loop(Looper.java:130)
07-23 23:33:12.137: E/AndroidRuntime(1127): at android.app.ActivityThread.main(ActivityThread.java:3683)
07-23 23:33:12.137: E/AndroidRuntime(1127): at java.lang.reflect.Method.invokeNative(Native Method)
07-23 23:33:12.137: E/AndroidRuntime(1127): at java.lang.reflect.Method.invoke(Method.java:507)
07-23 23:33:12.137: E/AndroidRuntime(1127): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
07-23 23:33:12.137: E/AndroidRuntime(1127): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
07-23 23:33:12.137: E/AndroidRuntime(1127): at dalvik.system.NativeStart.main(Native Method)
07-23 23:33:12.137: E/AndroidRuntime(1127): Caused by: java.lang.ClassNotFoundException: ishan.khandelwal.vitsilentmode.receiver.StartMyServiceAtBootReceiver in loader dalvik.system.PathClassLoader[/data/app/ishan.khandelwal.vitsilentmode-1.apk]
07-23 23:33:12.137: E/AndroidRuntime(1127): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
07-23 23:33:12.137: E/AndroidRuntime(1127): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
07-23 23:33:12.137: E/AndroidRuntime(1127): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
07-23 23:33:12.137: E/AndroidRuntime(1127): at android.app.ActivityThread.handleReceiver(ActivityThread.java:1764)
07-23 23:33:12.137: E/AndroidRuntime(1127): ... 10 more
Thanks for the help in advance.
Ok, the problem is that you have specified in your AndroidManifest the wrong/a nonexistent receiver implementation. You specified this:
<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>
The problem is you have no class called StartMyServiceAtBootReceiver. What you I think you should have is something like this:
<receiver
android:name=".AlarmReceiver"
android:enabled="true"
android:exported="true"
android:label="StartMyServiceAtBootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
I am trying to open the download's folder programmatically. But, I keep getting ActivityNotFoundException. I have seen various questions on this on StackOverflow, tried most of them, but nothing worked till now. Here is my code below
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(downloadDirectoryPath));
startActivity(intent);
AndroidManifest.xml - related code
<activity
android:name="com.xx.xxx.videowebview.VideoWebViewActivity"
android:configChanges="orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:hardwareAccelerated="true"
android:label="#string/app_name"
android:theme="#style/custom_theme" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
I think I have set the required things in manifest too, but, I still keep getting the Exception.
I have a download button in VideoWebViewActivity, when clicked, downloads a file and then has to open the download folder on the device. Is setting, category to DEFAULT as above, correct? or should I be using a new activity(I don't really need any other activity, so should I be using a dummy activity? Doesn't sound right...)?
Here is my LogCat...
03-28 15:17:37.349: E/AndroidRuntime(15791): FATAL EXCEPTION: main
03-28 15:17:37.349: E/AndroidRuntime(15791): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=/mnt/sdcard/download/ }
03-28 15:17:37.349: E/AndroidRuntime(15791): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1409)
03-28 15:17:37.349: E/AndroidRuntime(15791): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379)
03-28 15:17:37.349: E/AndroidRuntime(15791): at android.app.Activity.startActivityForResult(Activity.java:2827)
03-28 15:17:37.349: E/AndroidRuntime(15791): at android.app.Activity.startActivity(Activity.java:2933)
03-28 15:17:37.349: E/AndroidRuntime(15791): at com.xx.xxx.videowebview.VideoWebViewActivity$DownloadFile.onPostExecute(VideoWebViewActivity.java:442)
03-28 15:17:37.349: E/AndroidRuntime(15791): at com.xx.xxx.videowebview.VideoWebViewActivity$DownloadFile.onPostExecute(VideoWebViewActivity.java:1)
03-28 15:17:37.349: E/AndroidRuntime(15791): at android.os.AsyncTask.finish(AsyncTask.java:417)
03-28 15:17:37.349: E/AndroidRuntime(15791): at android.os.AsyncTask.access$300(AsyncTask.java:127)
03-28 15:17:37.349: E/AndroidRuntime(15791): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429)
03-28 15:17:37.349: E/AndroidRuntime(15791): at android.os.Handler.dispatchMessage(Handler.java:99)
03-28 15:17:37.349: E/AndroidRuntime(15791): at android.os.Looper.loop(Looper.java:130)
03-28 15:17:37.349: E/AndroidRuntime(15791): at android.app.ActivityThread.main(ActivityThread.java:3687)
03-28 15:17:37.349: E/AndroidRuntime(15791): at java.lang.reflect.Method.invokeNative(Native Method)
03-28 15:17:37.349: E/AndroidRuntime(15791): at java.lang.reflect.Method.invoke(Method.java:507)
03-28 15:17:37.349: E/AndroidRuntime(15791): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878)
03-28 15:17:37.349: E/AndroidRuntime(15791): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636)
03-28 15:17:37.349: E/AndroidRuntime(15791): at dalvik.system.NativeStart.main(Native Method)
I haven't yet figured it out, but, for now, I am directly opening the file that I downloaded using the below code...
File file = new File(path);
Uri uri_path = Uri.fromFile(file);
String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension
(MimeTypeMap.getFileExtensionFromUrl(path));
Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
intent.setType(mimeType);
intent.setDataAndType(uri_path, mimeType);
startActivity(intent);
path = the path of the FILE(not directory) that you want to open.
Will update the answer, if I get to open the directory successfully.
I am trying to retrieve specific data like custom ads, username, date etc from database. so followed the code from this Need a simple tutorial for android/webservice work?. I'm going wrong some where can any one help as i am new to android.Getting following errors
11-13 21:57:14.720: E/AndroidRuntime(399): FATAL EXCEPTION: main
11-13 21:57:14.720: E/AndroidRuntime(399): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.response/com.response.FetchList}: java.lang.ClassCastException: com.response.FetchList
11-13 21:57:14.720: E/AndroidRuntime(399): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
11-13 21:57:14.720: E/AndroidRuntime(399): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
11-13 21:57:14.720: E/AndroidRuntime(399): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
11-13 21:57:14.720: E/AndroidRuntime(399): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
11-13 21:57:14.720: E/AndroidRuntime(399): at android.os.Handler.dispatchMessage(Handler.java:99)
11-13 21:57:14.720: E/AndroidRuntime(399): at android.os.Looper.loop(Looper.java:123)
11-13 21:57:14.720: E/AndroidRuntime(399): at android.app.ActivityThread.main(ActivityThread.java:4627)
11-13 21:57:14.720: E/AndroidRuntime(399): at java.lang.reflect.Method.invokeNative(Native Method)
11-13 21:57:14.720: E/AndroidRuntime(399): at java.lang.reflect.Method.invoke(Method.java:521)
11-13 21:57:14.720: E/AndroidRuntime(399): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-13 21:57:14.720: E/AndroidRuntime(399): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
11-13 21:57:14.720: E/AndroidRuntime(399): at dalvik.system.NativeStart.main(Native Method)
11-13 21:57:14.720: E/AndroidRuntime(399): Caused by: java.lang.ClassCastException: com.response.FetchList
11-13 21:57:14.720: E/AndroidRuntime(399): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
11-13 21:57:14.720: E/AndroidRuntime(399): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
Edit-
Manifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.response"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".Response"
android:label="#string/title_activity_response" >
<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" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="android.support.v4.app.FragmentActivity" />
</activity>
<activity
android:name=".XMLParser"
android:label="#string/title_activity_response" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".FetchList"
android:label="#string/title_activity_response" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
If you've taken the code from that link exactly as-is, then you could be running into that error at the line,
public class FetchList extends asyncTask<Void,Void,Byte>{
doinbackground{
Which would actually be
public class FetchList extends asyncTask<Void, Void, Byte> {
#Override
protected Byte doInBackground (Void... voids){
...
}
}
EDIT: From the code in your comment,
public class FetchList extends AsyncTask<Void,Void,Byte>{
#Override
protected Byte doInBackground1(Void... arg0){
// this was explained in first step
Response res = new Response("url");
String response = res.getResponse();
XMLParser xml = new XMLParser(response);
ArrayList<XMLParser> itemList = xml.getItemList();
return xml.parse();
}
}
In this case let me know what the Logcat output is.
I've started to learn Android Development and I got this snippit off of google android development site, it keeps on crashing.
My specs are:
Android 4.0.3
API 15
Code:
package lewes.android.hello;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class HelloAndroid extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView tv = new TextView(this);
tv.setText("Hello, Android");
setContentView(tv);
}
}
I get...
Unfortenualy, HelloAndroid is not responding.
Please help me!
MY MANIFEST:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="lewes.android.hello"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="15" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".HelloWorld"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
LogCat:
03-17 11:35:19.835: D/AndroidRuntime(562): Shutting down VM
03-17 11:35:19.835: W/dalvikvm(562): threadid=1: thread exiting with uncaught
exception (group=0x409c01f8)
03-17 11:35:19.914: E/AndroidRuntime(562): FATAL EXCEPTION: main
03-17 11:35:19.914: E/AndroidRuntime(562): java.lang.RuntimeException: Unable to
instantiate activity
ComponentInfo{lewes.android.hello/lewes.android.hello.HelloWorld}:
java.lang.ClassNotFoundException: lewes.android.hello.HelloWorld
03-17 11:35:19.914: E/AndroidRuntime(562): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1880)
03-17 11:35:19.914: E/AndroidRuntime(562): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
03-17 11:35:19.914: E/AndroidRuntime(562): at
android.app.ActivityThread.access$600(ActivityThread.java:123)
03-17 11:35:19.914: E/AndroidRuntime(562): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
03-17 11:35:19.914: E/AndroidRuntime(562): at
android.os.Handler.dispatchMessage(Handler.java:99)
03-17 11:35:19.914: E/AndroidRuntime(562): at android.os.Looper.loop(Looper.java:137)
03-17 11:35:19.914: E/AndroidRuntime(562): at
android.app.ActivityThread.main(ActivityThread.java:4424)
03-17 11:35:19.914: E/AndroidRuntime(562): at
java.lang.reflect.Method.invokeNative(Native Method)
03-17 11:35:19.914: E/AndroidRuntime(562): at
java.lang.reflect.Method.invoke(Method.java:511)
03-17 11:35:19.914: E/AndroidRuntime(562): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
03-17 11:35:19.914: E/AndroidRuntime(562): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
03-17 11:35:19.914: E/AndroidRuntime(562): at dalvik.system.NativeStart.main(Native
Method)
03-17 11:35:19.914: E/AndroidRuntime(562): Caused by:
java.lang.ClassNotFoundException: lewes.android.hello.HelloWorld
03-17 11:35:19.914: E/AndroidRuntime(562): at
dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
03-17 11:35:19.914: E/AndroidRuntime(562): at
java.lang.ClassLoader.loadClass(ClassLoader.java:501)
03-17 11:35:19.914: E/AndroidRuntime(562): at
java.lang.ClassLoader.loadClass(ClassLoader.java:461)
03-17 11:35:19.914: E/AndroidRuntime(562): at
android.app.Instrumentation.newActivity(Instrumentation.java:1023)
03-17 11:35:19.914: E/AndroidRuntime(562): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1871)
03-17 11:35:19.914: E/AndroidRuntime(562): ... 11 more
03-17 11:40:20.114: I/Process(562): Sending signal. PID: 562 SIG: 9
Delete one of the application sections from your manifest.
Keep the one where the activity corresponds to the name of your class.
make your manifest look exactly like this
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="lewes.android.hello"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="15" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".HelloAndroid"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Change
<activity
android:name=".HelloAndroidActivity"
to
<activity
android:name=".HelloAndroid"
SDK does not mention about this. But as my experience, activity (this) can not be used inside onCreate(Bundle) to initialize new objects. To be used as a parameter for constructors, this is nothing within onCreate().
You can follow this hello world. It uses static xml layout.
Hope this helps you :-)
I am trying to write an app that starts on boot up. My receiver works and my app is started on boot up, however it crashes because of ActivityNotFoundException. I may have messed up in the manifest somewhere. Please help to take a look.
This is the receiver code, LocationLock.class just does some stuff to lock the phone.
public class MyStartupIntentReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent){
Intent myStarterIntent = new Intent(context, LocationLock.class);
myStarterIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(myStarterIntent);
}
}
This is the manifest:
<?xml version="1.0" encoding="utf-8"?>
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".LocationLock$Controller"
android:label="#string/app_name_controller">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".LocationLock"
android:label="#string/app_name"
android:permission="android.permission.BIND_DEVICE_ADMIN">
<meta-data android:name="android.app.device_admin"
android:resource="#xml/device_admin" />
<intent-filter>
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
</intent-filter>
</receiver>
<receiver android:name=".MyStartupIntentReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
</application>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
</manifest>
Below are the errors:
05-03 02:54:55.301: ERROR/AndroidRuntime(264): FATAL EXCEPTION: main
05-03 02:54:55.301: ERROR/AndroidRuntime(264): java.lang.RuntimeException: Unable to start receiver org.example.locationlock.MyStartupIntentReceiver: android.content.ActivityNotFoundException: Unable to find explicit activity class {org.example.locationlock/org.example.locationlock.LocationLock}; have you declared this activity in your AndroidManifest.xml?
05-03 02:54:55.301: ERROR/AndroidRuntime(264): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2821)
05-03 02:54:55.301: ERROR/AndroidRuntime(264): at android.app.ActivityThread.access$3200(ActivityThread.java:125)
05-03 02:54:55.301: ERROR/AndroidRuntime(264): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2083)
05-03 02:54:55.301: ERROR/AndroidRuntime(264): at android.os.Handler.dispatchMessage(Handler.java:99)
05-03 02:54:55.301: ERROR/AndroidRuntime(264): at android.os.Looper.loop(Looper.java:123)
05-03 02:54:55.301: ERROR/AndroidRuntime(264): at android.app.ActivityThread.main(ActivityThread.java:4627)
05-03 02:54:55.301: ERROR/AndroidRuntime(264): at java.lang.reflect.Method.invokeNative(Native Method)
05-03 02:54:55.301: ERROR/AndroidRuntime(264): at java.lang.reflect.Method.invoke(Method.java:521)
05-03 02:54:55.301: ERROR/AndroidRuntime(264): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-03 02:54:55.301: ERROR/AndroidRuntime(264): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-03 02:54:55.301: ERROR/AndroidRuntime(264): at dalvik.system.NativeStart.main(Native Method)
05-03 02:54:55.301: ERROR/AndroidRuntime(264): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {org.example.locationlock/org.example.locationlock.LocationLock}; have you declared this activity in your AndroidManifest.xml?
05-03 02:54:55.301: ERROR/AndroidRuntime(264): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1404)
05-03 02:54:55.301: ERROR/AndroidRuntime(264): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
05-03 02:54:55.301: ERROR/AndroidRuntime(264): at android.app.ContextImpl.startActivity(ContextImpl.java:622)
05-03 02:54:55.301: ERROR/AndroidRuntime(264): at android.content.ContextWrapper.startActivity(ContextWrapper.java:258)
05-03 02:54:55.301: ERROR/AndroidRuntime(264): at android.content.ContextWrapper.startActivity(ContextWrapper.java:258)
05-03 02:54:55.301: ERROR/AndroidRuntime(264): at org.example.locationlock.MyStartupIntentReceiver.onReceive(MyStartupIntentReceiver.java:12)
05-03 02:54:55.301: ERROR/AndroidRuntime(264): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2810)
05-03 02:54:55.301: ERROR/AndroidRuntime(264): ... 10 more
Maybe I can't have two receivers listed one after another, but the MyStartupIntentReceiver has no activity associated with it.
Any help is much appreciated!
you are trying to start a receiver class: Intent myStarterIntent = new Intent(context, LocationLock.class);, since in the manifest file it is declared as a reciever class: <receiver android:name=".LocationLock" so modify this declaration to activiy:
<activity
android:name=".LocationLock"
android:windowSoftInputMode="stateVisible|adjustResize" >
</activity>
have you tried defining it as an activity in your manifest?
for example, within your section:
<activity android:name=".MyStartupIntentReceiver"
android:launchMode="singleTop"
android:screenOrientation="portrait"
android:noHistory="true" />