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.
Related
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);
I looked in to everything before ask this. I am implementing an application and new to android, I need to redirect to my mapview xml when login button click. So i have written the intent plus made the activity in manifest file and tried writing codes every possible different way. And the code doesn't give any errors. But my emulator stops after launching.
I know something is wrong but I can't figure it out. Any idea why that happens?
here is my code
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Button button=(Button)findViewById(R.id.loginbtn);
button.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
switch (v.getId()) {
case R.id.loginbtn:
Intent intent = new Intent (MainActivity.this, MapView.class);
startActivity (intent);
break;
default:
break;}
}
}
);
}
}
/*if(username.getText().toString()==""&&password.getText().toString()=="")
{
Intent i= new Intent("com.example.shaz.MAPVIEW");
startActivity(i);
}
else
{
txt.setText("False");
}
*/
Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myname"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="17"
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.myname.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=".mapView"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.example.myname.MAPVIEW" />
<category android:name="android.intent.category.DEFUALT" />
</intent-filter>
</activity>
</application>
</manifest>
I have also created an xml file for map called map_view in my layouts.
So in every where I searched this is how they say new intent is creating .
And the emulator works fine if I do something else than this redirection. SO what ever problem I got is within this redirection part.
DEFAULT is spelled incorrectly in your Manifest
Change:
<category android:name="android.intent.category.DEFUALT" />
for this:
<category android:name="android.intent.category.DEFAULT" />
I am having errors when attempting to add an onclick listener button to my current code. The original post where I found the code is listed below. Your assistance is greatly appreciated. I am comfortable with Java but still have trouble navigating with the Eclipse application. If anyone has any documentation that could help better prepare me that would be helpful.
android eclipse button OnClick event
MainActivity.java
Button btn = (Button) findViewById(R.id.btnPlay);
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
myClick(v); /* my method to call new intent or activity */
}
});
public void myClick(View v) {
Intent intent = new Intent(**this, Swipe.class**);
startActivity(intent);// for calling the activity
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.apptest"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.apptest.MainActivityAppTest"
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=".Swipe"
android:screenOrientation="landscape" >
</activity>
</application>
</manifest>
I think you are getting a compilation error right?
In this line Intent intent = new Intent(**this, Swipe.class**);
You should type Intent intent = new Intent(MainActivity.this, Swipe.class);
that should work
I am developing an Android app, in which I have to move to MapActivity on Button click event.
But the app is crashing while switching from Activity to MapActivity.
can anyone help me on this?
Thanks in advance.
Here is my code,
public class PopupActivity extends Activity implements GPSCallback
{
.......
public void display_map(String str)
{
Intent showMap_intent = new Intent(this,DisplayGoogleMaps.class);
PopupActivity.this.startActivity(showMap_intent);
}
}
This is my map Activity class
public class DisplayGoogleMaps extends MapActivity
{
MapView mapView;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.map);
}
}
And This is my Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.xxxx"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<uses-library android:name="com.google.android.maps" />
<activity
android:label="#string/app_name"
android:name=".PopupActivity" >
<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=".DisplayGoogleMaps" >
</activity>
</application>
</manifest>
there is nothing in error log while crashing!
Did you declare the map activity in your Manifest? Did you set the Android API package as Google APIs ?
These are mandatory.
What do you mean with "while switching from Activity to MapActivity"?
How do you switch? Any source code?
When you want to show some data in am MapView you have to start an Intent.
public void onClick(View view) {
Intent i = new Intent(this, ActivityTwo.class);
i.putExtra("Value1", "This value one for ActivityTwo ");
i.putExtra("Value2", "This value two ActivityTwo");
// Set the request code to any code you like, you can identify the
// callback via this code
startActivity(i);
}
From http://www.vogella.de/articles/AndroidIntent/article.html => 6. Tutorial: Explicit intents and data transfer between activities
In your case the class >ActivityTwo< has to be the MapActivity
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);
}
});