How do I resolve the ActivityNotFoundException? - android

I'm getting an ActivityNotFoundException in my Android Application.. Here's the code snippet I have put to call the activity :
Intent i = new Intent();
i.putExtra("NAME", username.getText().toString());
i.setClassName(getPackageName(), SecondActivity.class.getSimpleName());
startActivity(i);
my AndroidManifest.xml looks like this
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.rangde"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA"/>
<application android:icon="#drawable/ic_launcher" android:label="#string/app_name" >
<activity android:name=".firstActivity" android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:label="#string/app_name" android:name=".SecondActivity" />
<activity android:label="#string/app_name" android:name=".WelcomeActivity" />
</application>
</manifest>
When I execute the code snippet with the intent, I get the following exception.
E/AndroidRuntime(731): android.content.ActivityNotFoundException:
Unable to find explicit activity class {com.rangde/WelcomeActivity};
have you declared this activity in your AndroidManifest.xml?
Can someone tell me what I'm doing wrong?

//set your classname here
Intent i = new Intent(firstActivity.this, SecondActivity.class);
i.putExtra("NAME", username.getText().toString());
startActivity(i);

Call your SecondActvity like This
Intent i = new Intent(this,SecondActivity.class);
i.putExtra("NAME", username.getText().toString());
startActivity(i);

use this
String packageName = this.getPackageName();
i.setClassName(packageName ,packageName + "." + SecondActivity.class.getSimpleName());
instead of
i.setClassName(getPackageName(), SecondActivity.class.getSimpleName());

instead of writing
i.setClassName(getPackageName(), SecondActivity.class.getSimpleName());
try with
i.setClassName(getPackageName(), SecondActivity.class.getName());
SecondActivity.class.getSimpleName() returns only name of the class.
if u write SecondActivity.class.getName() get fully qualified class name(with the package name)

Intent intent = new Intent().setClass(Class1.this, Class2.class);
i.putExtra("NAME", username.getText().toString());
startActivity(intent);

Related

How to open an activity in a package subfolder from another activity?

I have problem with my manifest. When I try to open the second Activity, I get the error android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.xxxxx.monapplication.APPLICATION.OWNERREGISTRATION }
Find bellow my Manifest .xml contain
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.xxxxx.monapplication" android:versionCode="1" android:versionName="1.0" >
<uses-sdk android:minSdkVersion="15" android:targetSdkVersion="23" />
<application android:allowBackup="true" android:icon="#mipmap/ic_launcher" android:label="#string/app_name" android:supportsRtl="true" android:theme="#style/AppTheme" >
<activity android:name="com.xxxxx.monapplication.application.Accueil" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.xxxxx.monapplication.application.OwnerRegistration" >
<intent-filter>
<action android:name="android.intent.action.APPLICATION.OWNERREGISTRATION" />
<category android:name="android.intent.category.APPLICATION.DEFAULT" />
</intent-filter>
</activity>
An the part of my code to open second activity
btnMel.setOnClickListener( new View.OnClickListener()
{
#Override
public void onClick(View v)
{
Intent i = new Intent("com.xxxxx.monapplication.APPLICATION.OWNERREGISTRATION");
startActivity(i);
}
}
Please help me to find the error.
You can call activity by its class name, then put your custom intent to setAction.
private String YOUR_ACTION = "com.xxxxx.monapplication.APPLICATION.OWNERREGISTRATION"
//uou can use this instead.
//Intent i = new Intent(this /* caller context */, OwnerRegistration.class);
Intent i = new Intent();
i.setAction(YOUR_ACTION);
startActivity(i);
try this code..
Intent myIntent = new Intent(YourActivity.this, OWNERREGISTRATION.class); startActivity(myIntent);

Android Studio, error with intents

I'm using Android Studio to write and run my android application but I run into this error when I try to go from one activity to another via intent, I either get this error:
android.content.ActivityNotFoundException: Unable to find explicit activity class
{com.example.rudrunk/junit.framework.Test}; have you declared this activity in your
AndroidManifest.xml?
or a NullPointerException if I use another intent.
My manifest file is below, but all the code comes from the IDE automatically, so I don't understand what's going on.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.rudrunk"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<application android:theme="#style/AppTheme" android:label="#string/app_name" android:icon="#drawable/ic_launcher" android:debuggable="true" android:allowBackup="true">
<activity android:label="#string/app_name" android:name="com.example.rudrunk.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:label="#string/title_activity_test" android:name="com.example.rudrunk.Test" />
<activity android:label="#string/title_activity_drunk_test" android:name="com.example.rudrunk.DrunkTest" />
</application>
Java Code for intents:
final Intent localIntent1 = new Intent(MainActivity.this, DrunkTest.class);
final Intent localIntent2 = new Intent(MainActivity.this, Test.class);
Button localButton1 = (Button)findViewById(R.id.maybe);
Button localButton2 = (Button)findViewById(R.id.yes);
localButton1.setOnClickListener(new View.OnClickListener()
{
public void onClick(View paramAnonymousView)
{
startActivity(localIntent1);
}
});
localButton2.setOnClickListener(new View.OnClickListener()
{
public void onClick(View paramAnonymousView)
{
Intent localIntent = new Intent("android.intent.action.CALL");
localIntent2.setData(Uri.parse("tel:16097212155"));
startActivity(localIntent2);
}
});
Looks like Test.class is being resolved into junit.framework.Test instead of your Activity. This could be a wrong import (import junit.framework.Test;?) but the sure way to make it work would be to use the full class name, i.e.
new Intent(MainActivity.this, com.example.rudrunk.Test.class);
In any case, it should match the class name in the AndroidManifest file.

override an activity on another

1This is my code snippet
TabHost tabHost = getTabHost();
TabSpec aboutus = tabHost.newTabSpec("About us");
aboutus.setIndicator("___", getResources().getDrawable(R.drawable.icon_aboutus_tab));
Intent photosIntent = new Intent(getApplicationContext(), readmore.class);
aboutus.setContent(photosIntent);
TabSpec contactus = tabHost.newTabSpec("Contact us");
// setting Title and Icon for the Tab
contactus.setIndicator("___", getResources().getDrawable(R.drawable.icon_contactus_tab));
Intent songsIntent = new Intent(getApplicationContext(), contactus.class);
contactus.setContent(songsIntent);
TabSpec orderhistory = tabHost.newTabSpec("Order history");
orderhistory.setIndicator("___", getResources().getDrawable(R.drawable.icon_orderhistory_tab));
Intent videosIntent = new Intent(getApplicationContext(), readmore.class);
orderhistory.setContent(videosIntent);
TabSpec home = tabHost.newTabSpec("Home");
home.setIndicator("___", getResources().getDrawable(R.drawable.icon_home_tab));
Intent homeIntent = new Intent(getApplicationContext(), Mainpage.class);
homeIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
homeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
homeIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
home.setContent(homeIntent);
// Adding all TabSpec to TabHost
tabHost.addTab(aboutus); // Adding about us tab
tabHost.addTab(contactus); // Adding contact us tab
tabHost.addTab(orderhistory); // Adding order history tab
tabHost.addTab(home);
The Intent is not overriding the main activity.
how am i supposed to override it.
This is my manifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.androidhive.xmlparsing"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.CLEAR_APP_CACHE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application
android:icon="#drawable/zaggleicon"
android:label="#string/app_name"
android:name=".MyApplication"
android:theme="#android:style/Theme.Light"
>`<activity
android:label="#string/app_name"
android:name=".AndroidTabLayoutActivity" >
<intent-filter >
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>`<activity
android:label="#string/app_name"
android:name=".readmore" >
<intent-filter >
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>` <activity android:name=".Mainpage">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>`<activity
android:label="#string/app_name"
android:name=".contactus" >
<intent-filter >
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>`
From my image it is showing that when i press the button the activit is showing in particular portion and the last activity remains same in the activity.So how to override that activty when i press the tab button.
Simply declare you tab's activities as per below -
<activity
android:label="#string/app_name"
android:name=".readmore"> </activity>
<activity android:name=".Mainpage"></activity>
<activity
android:label="#string/app_name"
android:name=".contactus" ></activity>
And, have a look at TabLayout tutorial.

Android app crash: Unable to instantiate activity ComponentInfo

07-18 04:48:22.465: E/AndroidRuntime(19105): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.liamwli.fa.yearbook/com.liamwli.fa.yearbook.Home}: java.lang.NullPointerException
That is the error I get.
I have defined the Home class in the manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.liamwli.fa.yearbook"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
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/app_name"
android:theme="#android:style/Theme.Holo" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Home"
android:label="#string/app_name"
android:theme="#android:style/Theme.Holo" >
<intent-filter>
<action android:name="com.liamwli.fa.yearbook.HOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
And it only started doing this when I added the putExtras line in my main activity:
enter.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
myname = name.getText().toString();
Intent i = new Intent("com.liamwli.fa.yearbook.HOME");
i.putExtra("myname", myname);
startActivity(i);
}
});
So, can anyone please explain what is happening?
use this:
Intent i = new Intent(context,otherActivity.class);
context of that activity from where you want to start activity.otherActivity is the name of activity which you want to start
Try this once
Intent i = new Intent(MainActivity.this,Home.class);
i.putExtra("myname", myname);
startActivity(i);
And I don't think this is required in Manifest
<intent-filter>
<action android:name="com.liamwli.fa.yearbook.HOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
change like this
Intent i = new Intent(MainActivity.this, Home.class);
i.putExtra("myname", myname);
startActivity(i);
Try this...
Intent i = new Intent( YourActivityName.this , otherActivity.class);
Ok, I looked and it looked like I was setting a variable contents outside of the onCreate method. So that is why it wasn't working.

How to launch an Android app without "android.intent.category.LAUNCHER"

I want to know how to launch an Android app without:
android.intent.category.LAUNCHER
Here is my AndroidManifest.xml:
<intent-filter>
<action android:name = "android.intent.action.MAIN" />
<category android:name = "android.intent.category.LAUNCHER" />
</intent-filter>
If removing line 3, the app will not be in the launcher. The question is: where and how can I launch this app in other way?
You'll need to use a BroadcastReceiver.
public class SafetyReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
ActivityManager as = (ActivityManager) context
.getSystemService(Activity.ACTIVITY_SERVICE);
if (IsNavigationRunning(as)) {
Intent i = new Intent(context, VoiceActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
}
Manifest:
<application
android:icon="#drawable/fot"
android:label="#string/app_name" >
<activity
android:name="com.Safety.VoiceActivity"
android:launchMode="singleTop"
android:theme="#style/Theme.CompletelyTransparentWindow" >
</activity>
<receiver
android:name="com.Safety.SafetyReceiver"
android:process=":goodprocess" >
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
</application>
This is an example that starts when a text is received.
This would be better if you want to launch a custom activity, for example on a button press:
Button btn = (Button)findViewById(R.id.xBtn);
btn.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v)
{
Intent intent = new Intent("it.prassel.vimsmediaplayer");
intent.setComponent(ComponentName
.unflattenFromString("it.prassel.vimsmediaplayer/it.prassel.vimsmediaplayer.MainActivity"));
intent.addCategory("android.intent.category.LAUNCHER");
startActivity(intent);
}
});
And this is the manifest associated with your custom activity:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="it.prassel.vimsmediaplayer"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-feature android:glEsVersion="0x00020000" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="it.prassel.vimsmediaplayer.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="it.prassel.vimsmediaplayer" />
</intent-filter>
</activity>
</application>
</manifest>
Where
Intent intent = new Intent("it.prassel.vimsmediaplayer");
corresponds to the line
<action android:name="it.prassel.vimsmediaplayer" />
And
intent.setComponent(ComponentName
.unflattenFromString("it.prassel.vimsmediaplayer/it.prassel.vimsmediaplayer.MainActivity"))
corresponds to the 2 lines
package="it.prassel.vimsmediaplayer" the part before /
android:name="it.prassel.vimsmediaplayer.MainActivity" the part after /
Your custom activity will not appear neither in the Menu nor in the Recent Apps, it will be completely anonymous. Pay attention, if you wish to be the only one who can acced to your app, to give the intent-filter a meaningful name
I want to know how to launch an Android app without: android.intent.category.LAUNCHER
In Android, an Activity should be started by an Intent. Intents can start an Activity with startActivity(Intent myIntent), example:
Intent myIntent= new Intent(context, target_class.class);
myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(myIntent);
You must replace "myIntent", "context" (usually a "this") and the "target_class" with your variables, in order for this to work.
So, whenever you need your activity, call the Intent, ans the OS will resolve for the Activity
you can specify in your class.
For example on clicking of a button you want to go to some activity. so just write this code:
Button btn = (Button)findViewById(R.id.xBtn);
btn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent intnt = new Intent();
intnt.setAction(android.intent.action.MAIN);
intnt.setCategory(android.intent.category.LAUNCHER);
startActivity(intnt);
}
});

Categories

Resources