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

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);

Related

intent not working i cant start another activity

complete newbie here .. im creating my first android quiz game.
i would like to start another activity if button is clicked. (from mainactivity to quizactivity)
i used intent for this but when i try to run it on device and i click on the button, the game crashes . a little help please
here is my main activity
package com.example.clicktothink;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity{
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btn= (Button)findViewById(R.id.play_btn);
btn.setOnClickListener(new OnClickListener()
{ public void onClick(View v)
{
Intent intent = new Intent(MainActivity.this, QuizActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent);
}
});
}
}
and here is my manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.clicktothink"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.clicktothink.QuizActivity"
android:label="#string/app_name"
android:parentActivityName="com.example.clicktothink.MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.clicktothink.MainActivity" />
</activity>
<activity
android:name="com.example.clicktothink.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>
</application>
</manifest>
please check your mainfest and change that to this .
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.clicktothink"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.clicktothink.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="com.example.clicktothink.QuizActivity"/>
</application>
</manifest>
btn.setOnClickListener(new OnClickListener()
{ public void onClick(View v)
{
Intent intent = new Intent(MainActivity.this, QuizActivity.class);
startActivity(intent);
}
});
instead of this
Intent intent = new Intent(MainActivity.this, QuizActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent);
change to this
Intent intent = new Intent(MainActivity.this, QuizActivity.class);
startActivity(intent);

Why Button click redirection for another xml page is not working?

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" />

Preparing a button for Onclick() listener

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

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 do I resolve the ActivityNotFoundException?

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);

Categories

Resources