Android: unable to find explicit activity class? - android

Within my application I am getting the following error from logcat, What is the error with my code? I have searched for over an hour online and cannot solve the issue.
It is relating to the intent that I am trying to use in order to open up a new activity but I am not sure how to solve it.
07-20 20:02:18.976: E/AndroidRuntime(7381): FATAL EXCEPTION: Thread-9022
07-20 20:02:18.976: E/AndroidRuntime(7381): Process: com.example.brianapp, PID: 7381
07-20 20:02:18.976: E/AndroidRuntime(7381): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.example.brianapp.MeditationResults }
07-20 20:02:18.976: E/AndroidRuntime(7381): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1672)
07-20 20:02:18.976: E/AndroidRuntime(7381): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1442)
07-20 20:02:18.976: E/AndroidRuntime(7381): at android.app.Activity.startActivityForResult(Activity.java:3511)
07-20 20:02:18.976: E/AndroidRuntime(7381): at android.app.Activity.startActivityForResult(Activity.java:3472)
07-20 20:02:18.976: E/AndroidRuntime(7381): at android.app.Activity.startActivity(Activity.java:3714)
07-20 20:02:18.976: E/AndroidRuntime(7381): at android.app.Activity.startActivity(Activity.java:3682)
07-20 20:02:18.976: E/AndroidRuntime(7381): at com.example.brianapp.Meditation$2.run(Meditation.java:115)
It is relating from this code section as this error only occured once I changed this code section:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.meditation);
//new thread
Thread timer = new Thread() {
/**
* Method that firstly starts the thread and makes it sleep,
* then using intents opens the main activity using
* a reference to its name
*/
public void run() {
try {
//sleep for 3.5 seconds
sleep(15000);
} catch (InterruptedException e) {
// exceptions caught here
e.printStackTrace();
} finally {
Intent openActivity = new Intent("com.example.brianapp.MeditationResults");
// //Start activity
startActivity(openActivity);
}
}
};
//Start timer
timer.start();
The following is my manifest, note that I have included an intent filter for this class (meditation), the class I am trying to open with the intent is called MeditationResults:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.brianapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.brianapp.Menu"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.example.brianapp.menu" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.example.brianapp.Meditation"
android:label="Meditation" >
<intent-filter>
<action android:name="com.example.brianapp.meditation" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.example.brianapp.MeditationResults"
android:label="#string/title_activity_meditation_results" >
</activity>
<activity
android:name="com.example.brianapp.UserName"
android:label="#string/title_activity_user_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.brianapp.ServerInterface"
android:label="#string/title_activity_server_interface" >
</activity>
</application>
</manifest>

Change this in your manifest to
<activity
android:name="com.example.brianapp.MeditationResults"
android:label="#string/title_activity_meditation_results" >
</activity>
to
<activity
android:name="com.example.brianapp.MeditationResults"
android:label="#string/title_activity_meditation_results" >
<intent-filter>
<action android:name="com.example.brianapp.MeditationResults" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>

Related

Android custom scheme not working

Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.kt.myapplication" >
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".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=".ViewerActivity"
android:label="#string/title_activity_viewer" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="myapp" />
</intent-filter>
</activity>
</application>
</manifest>
MainActivity.java
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.main_txt).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.addCategory(Intent.CATEGORY_BROWSABLE);
intent.setData(Uri.parse("myapp://"));
startActivity(intent);
}
});
}
}
ViewerActivity.java
public class ViewerActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_viewer);
}
}
Error log...
03-02 09:37:59.753 21103-21103/com.example.kt.myapplication E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.kt.myapplication, PID: 21103
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW cat=[android.intent.category.BROWSABLE] dat=myapp:// }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1672)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1442)
at android.app.Activity.startActivityForResult(Activity.java:3511)
at android.app.Activity.startActivityForResult(Activity.java:3472)
at android.app.Activity.startActivity(Activity.java:3714)
at android.app.Activity.startActivity(Activity.java:3682)
at com.example.kt.myapplication.MainActivity$1.onClick(MainActivity.java:26)
at android.view.View.performClick(View.java:4630)
at android.view.View$PerformClick.run(View.java:19331)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5356)
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:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
I don't know why don't run...
please help me...
For some reason it seems like Android do not allow you to have only Browsable category in the intent filter declaration, try this instead:
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:scheme="somettt"/>
</intent-filter>
And launch it as expected:
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.addCategory(Intent.CATEGORY_BROWSABLE);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setData(Uri.parse("somettt://"));
startActivity(intent);
It should work now...
EDIT: This is why it works with DEFAULT as per Google's:
CATEGORY_DEFAULT
Set if the activity should be an option for the default action (center
press) to perform on a piece of data. Setting this will hide from the
user any activities without it set when performing an action on some
data. Note that this is normally -not- set in the Intent when
initiating an action -- it is for use in intent filters specified in
packages.
Regards!

Timer Not working in Android Eclipse

Timer is not working. after few second it should goto another activity
public class intro extends Activity {
int count=0;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.intro);
final Toast tosta = Toast.makeText(this, String.valueOf(count+"."), Toast.LENGTH_SHORT);
final Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
#Override
public void run() {
count++;
if(count == 5){
Intent app = new Intent("com.jasrajcomputers.MainActivity");
startActivity(app);
}
tosta.show();
}
}, 1000, 1000);
}}
but after 5 sec app unfortunately has stopped.
manifext.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.jasrajcomputers"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:theme="#style/noactionbarvirat"
android:label="#string/app_name" >
<activity
android:name=".intro"
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>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.jasrajcomputers.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.jasrajcomputers.MainActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
MY LOGCAT:
07-12 12:46:38.979: E/AndroidRuntime(14495): FATAL EXCEPTION: Timer-0
07-12 12:46:38.979: E/AndroidRuntime(14495): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.jasrajcomputers.MainActivity }
07-12 12:46:38.979: E/AndroidRuntime(14495): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1697)
07-12 12:46:38.979: E/AndroidRuntime(14495): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1492)
07-12 12:46:38.979: E/AndroidRuntime(14495): at android.app.Activity.startActivityForResult(Activity.java:3388)
07-12 12:46:38.979: E/AndroidRuntime(14495): at android.app.Activity.startActivityForResult(Activity.java:3349)
07-12 12:46:38.979: E/AndroidRuntime(14495): at android.app.Activity.startActivity(Activity.java:3584)
07-12 12:46:38.979: E/AndroidRuntime(14495): at android.app.Activity.startActivity(Activity.java:3552)
07-12 12:46:38.979: E/AndroidRuntime(14495): at com.jasrajcomputers.intro$1.run(intro.java:72)
07-12 12:46:38.979: E/AndroidRuntime(14495): at java.util.Timer$TimerImpl.run(Timer.java:284)
Just have
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:theme="#style/noactionbarvirat"
android:label="#string/app_name" >
<activity
android:name=".intro"
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>
Use Explicit intents
Intent app = new Intent(intro.this, MainActivity.class);
Remove
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.jasrajcomputers.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.jasrajcomputers.MainActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
Update :
Timer is not required here. You can use a Handler instead.
Quoting docs
Explicit intents specify the component to start by name (the
fully-qualified class name). You'll typically use an explicit intent
to start a component in your own app, because you know the class name
of the activity or service you want to start. For example, start a new
activity in response to a user action or start a service to download a
file in the background.
Use a Handler
new Handler().postDelayed(new Runnable(){
#Override
public void run() {
Intent app = new Intent("com.example.MainActivity");
startActivity(app);
}
}, 5000);
Try to replace this code :
Intent app = new Intent("com.jasrajcomputers.MainActivity");
With this code :
Intent app = new Intent(intro.this,MainActivity.class);
Note :
MainActivity must be define in AndroidManifest.xml

Android Splash activity not redirecting

I have created a splash activity for my app. I am trying to redirect from my Splash activity to the Starting Point activity using AndroidManifest.xml but its not working. The Splash class loads up, and then it doesn't redirect to the Starting Point. And it doesn't give any errors either.
So can you please help me figure it out.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp"
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.myapp.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="com.example.myapp.StartingPoint"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.example.myapp.STARTINGPOINT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
Now I have also tried
<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=".StartingPoint"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.example.myapp.STARTINGPOINT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
So what can I do here. I am not getting redirected from Splash to my Starting Point.
Splash Code
package com.example.myapp;
import android.app.Activity;
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);
}
}
Add this code to your Splash.java
Thread timer = new Thread(){
public void run(){
try {
sleep(2000);
} catch (Exception e) {
// TODO: handle exception
} finally{
Intent i = new Intent(Flash_Activity.this, StartingPoint.class);
startActivity(i);
}
}
};
timer.start();
}
You are never calling anything to change the activity from your splash to the starting point. This thread will do that.
Use this easy way to redirect to acitvity
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
Intent intent = new Intent(this,MainActivity.class);
startActivity(intent);
finish();
}
},2500);

Android app force closing after splash screen

I have a splash screen with a timer that runs for 3 seconds. After the 3 seconds it is supposed to auto load another activity called Dashboard. I made a new class that I want to have load after the splash screen called WelcomeSplash. I changed the classes in the splash screen from Dashboard to WelcomeSplash and the app force closes and the logcat says it has a null point exception. Here is the snip of code from the splash class and logcat snip.
02-13 23:18:46.826: E/AndroidRuntime(2475): FATAL EXCEPTION: main
02-13 23:18:46.826: E/AndroidRuntime(2475): java.lang.RuntimeException: Unable to start
activity ComponentInfo{com.magicbuddy.gamble/com.magicbuddy.gamble.welcomeSplash}:
java.lang.NullPointerException
02-13 23:18:46.826: E/AndroidRuntime(2475): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
Here is the snip of the Splash code
startActivity(new Intent(Splash.this, welcomeSplash.class));
When I change the welcomeSPlash.class to Dashboard.class the app does not force close. Here is the welcomeSplash Activity,
public class welcomeSplash extends Activity implements OnClickListener {
Button btnskip;
Button btnplay;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.welcome);
btnskip =(Button) findViewById(R.id.btnSkip);
btnskip.setOnClickListener(this);
btnplay =(Button) findViewById(R.id.btnOk);
btnplay.setOnClickListener(this);
}
public void onClick(View v) {
switch (v.getId()) {
case R.id.btnSkip:
Intent a = new Intent(welcomeSplash.this, Dashboard.class);
startActivity(a);
break;
case R.id.btnOk:
Intent i = new Intent(welcomeSplash.this, Profile.class);
startActivity(i);
break;
}
}
}
THe manifest is copied below too.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.magicbuddy.gamble"
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.magicbuddy.gamble.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="com.magicbuddy.gamble.welcomeSplash"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.magicbuddy.gamble.Dashboard" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.magicbuddy.gamble.Dashboard"
android:label="#string/app_name" >
</activity>
<activity
android:name="com.magicbuddy.gamble.MainActivity"
android:label="#string/app_name" >
</activity>
<activity
android:name="com.magicbuddy.gamble.Player"
android:label="#string/app_name" >
</activity>
<activity
android:name="com.magicbuddy.gamble.Menu"
android:label="#string/app_name" >
</activity>
<activity
android:name="com.magicbuddy.gamble.Popup"
android:label="#string/title_activity_popup" >
</activity>
</application>
</manifest>
Remove this code from your menifest
<intent-filter>
<action android:name="com.magicbuddy.gamble.Dashboard" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>

Not allowed to start service Intent

I'm trying to call a service from a activity:
When I'm running the program the activity throws an error which says: Not allowed to start service Intent. What am I doing wrong? I'm sorry for possible stupid mistakes in the code, but I'm a newbie.
activity code:
public void startService() {
try {
startService (new Intent ( this , SmsReminderService.class)) ; }
catch (Exception e ) { Log.v("Error" , e.getMessage()) }
}
service code :
public class SmsReminderService extends Service {
#Override
public void onStart(Intent intent, int startid) {
Log.v("SSms", "Service started") ; }}
manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="me.sms.smsReminder"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
<permission android:name="SEND_SMS"></permission>
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:label="#string/app_name"
android:name=".SmsReminderActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name=".SmsReminderService"
android:permission="android.permission.BIND_REMOTEVIEWS">
<intent-filter>
<action android:name = "android.intent.category.LAUNCHER" ></action>
</intent-filter>
</service>
</application>
</manifest>
Thanks in advance, Tom
Why this in the service?
<intent-filter>
<action android:name = "android.intent.category.LAUNCHER" ></action>
</intent-filter>
Try to add this:
<uses-permission android:name="android.permission.BIND_REMOTEVIEWS" />

Categories

Resources