Unable to start activity no activity found to start intent - android

I am trying to open a splash activity followed by main activity. But i am getting the following error in logcat.
01-20 16:46:45.568: E/AndroidRuntime(29579): FATAL EXCEPTION: main
01-20 16:46:45.568: E/AndroidRuntime(29579): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.cyoa.necroprelude/com.cyoa.necroprelude.MainActivity}: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.cyoa.necroprelude.CHARACTER }
Activity code - Main Activity
package com.cyoa.necroprelude;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class MainActivity extends Activity {
Intent openStartingPoint;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
run();
}
private void run() {
Intent openStartingPoint = new Intent("com.cyoa.necroprelude.CHARACTER");
startActivity(openStartingPoint);
}
}
Activity code - Character Activity
package com.cyoa.necroprelude;
import android.app.Activity;
import android.os.Bundle;
public class Character extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.character);
}
}
here is the manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.cyoa.necroprelude"
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.cyoa.necroprelude.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.cyoa.necroprelude.Character"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.CHARACTER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>

Change
Intent openStartingPoint = new Intent("com.cyoa.necroprelude.CHARACTER");
to
Intent openStartingPoint = new Intent(this, CHARACTER.class);
String CUSTOM_ACTION = "android.intent.action.CHARACTER";
openStartingPoint.setAction(CUSTOM_ACTION);

When creating an intent that opens another screen make sure it looks something like the following
Intent intent = new Intent(thisScreen.this, newScreen.class);
startActivity(intent);

Related

The activity must be exported or contain an intent-filter error

When I try to run the code I keep getting this error "The activity must be exported or contain an intent-filter".
I have set the small drop down beside the green run button to "app" and I have also put an intent-filter in my activity in the manifest. But this doesn't help. Hopefully someone can help me.
The code below is of my manifest file.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.brian.project">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".LoginSignupActivity.LoginActivity"
android:configChanges="orientation"
android:screenOrientation="portrait">
</activity>
<activity android:name=".HomeActivity"></activity>
<activity android:name=".LoginSignupActivity.SignupActivity"></activity>
<!--<activity android:name="WeightActivity"></activity>-->
</application>
</manifest>
My MainActivity code:
package com.example.brian.project;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import com.example.brian.project.LoginSignupActivity.LoginActivity;
import com.example.brian.project.LoginSignupActivity.SignupActivity;
public class MainActivity extends AppCompatActivity {
Button Login, Create_Account;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button Login=(Button) findViewById(R.id.btn_login);
Button Create_Account=(Button) findViewById(R.id.btn_create_account);
Login.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v){
openLoginActivity();
}
});
Create_Account.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v){
openSignupActivity();
}
});
}
public void openLoginActivity() {
Intent intent = new Intent(MainActivity.this, LoginActivity.class);
startActivity(intent);
}
public void openSignupActivity() {
Intent intent = new Intent(MainActivity.this, SignupActivity.class);
startActivity(intent);
}
}
Try to use android:exported="true" in the <activity> tag:
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

ActivityNotFoundException - Send Intent between two apps

I am trying to send an intent from the MainActivity of App A to the MainActivity of App B and then bring the App B to the front but when starting the App A I am getting the following error:
Caused by: android.content.ActivityNotFoundException: No Activity
found to handle Intent { act=com.example.app.MainActivity
pkg=com.example.app (has extras) }
First, I am starting the App B and then the App A.
How can I send an intent from the MainActivity of app A to the MainActivity of app B and then bringing the app B to the front ?
App A MainActivity:
package com.mysender;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String pdfString = "Hello World";
final Intent intent= new Intent("com.example.app.MainActivity");
intent.setPackage("com.example.app");
intent.putExtra("path", pdfString);
startActivity(intent);
}
}
App A Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mysender">
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
App B MainActivity:
package com.example.app;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
private WebView mWebView;
//private BroadcastReceiver myReceiver;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Bundle data = getIntent().getExtras();
if(data!=null){
String myString = data.getString("Id");
Toast.makeText(this,"Data Received from External App: " , Toast.LENGTH_SHORT).show();
}
}
App B Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.app" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen" >
<activity
android:name="com.example.app.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>
Error:
Caused by: android.content.ActivityNotFoundException: No Activity
found to handle Intent { act=com.example.app.MainActivity
pkg=com.example.app (has extras) }
final Intent intent= new Intent("com.example.app.MainActivity");
intent.setPackage("com.example.app");
intent.putExtra("path", pdfString);
startActivity(intent);
Caused by: android.content.ActivityNotFoundException: Unable to find
explicit activity class
{com.example.app/com.example.app.MainActivity}; have you declared this
activity in your AndroidManifest.xml?
final Intent intent= new Intent();
intent.setComponent(new ComponentName("com.example.app", "com.example.app.MainActivity"));
intent.putExtra("path", pdfString);
startActivity(intent);
Edit:
I have changed my manifest B to the following:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.app" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen" >
<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" />
<action android:name="com.mysender.Data"/>
</intent-filter>
</activity>
</application>
</manifest>
And the MainActivity of App A to:
package com.mysender;
import android.content.Intent;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String pdfString = "Hello World";
final Intent intent= new Intent("com.example.app.MainActivity");
intent.setPackage("com.example.app");
intent.setAction("com.mysender.Data");
intent.putExtra("path", pdfString);
startActivity(intent);
}
}
but I am still getting the error:
Caused by: android.content.ActivityNotFoundException: No Activity
found to handle Intent { act=com.mysender.Data pkg=com.example.app
(has extras) }

Application crashes upon new Activity

I know and I do understand that this question has been asked, but I can't seem to interpret it for my application. I am creating an application - using Android Studio - that opens a Activity (called 'About'). When a user clicks on the 'about button' on my MainActivity, it should launch the 'About' activity. However, when I test this out on my device, it says the app has stopped. And on my output panel, it says something about an error with my Manifest.xml file?
MainActivity:
package com.msp.supercarsounds;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void clickedAbout(View view) {
final int result = 1;
Intent AboutButtonClicked = new Intent (this, About.class);
AboutButtonClicked.putExtra("About", "MainActivity");
startActivityForResult(AboutButtonClicked, result);
}
}
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.msp.supercarsounds">
<uses-sdk android:minSdkVersion="17"
android:targetSdkVersion="22"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Thank you for your help and time!
You have to declare About activity
<activity android:name=".About">
</activity>
Add this below the </activity> tag of MainActivity
your second activity "about" is not added to manifest.xml add this under the mainactivity
<activity android:name=".about">/activity>

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

Application crash to start, when using BootReceiver

I want my application to launch browser when boot my tablet but its crashing on boot time. If someone please let me know my mistake? I write nothing in my activity_main.xmle. Its showing me message "unfortunately the application crashed".
mainfest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.autostartmyapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="#drawable/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>
<receiver android:name=".BootReciever" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
</application>
</manifest>
mainActivitc class
package com.example.autostartmyapp;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://google.com/"));
startActivity(browserIntent);
}
public class BootReciever extends BroadcastReceiver
{
#Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
Intent myIntent = new Intent(context, MainActivity.class);
myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(myIntent);
}
}
}
separate both classes and fix mainfest like below
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.autostartmyapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="#drawable/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>
<receiver
android:name="com.example.autostartmyapp.BootReciever"
android:enabled="true" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
</application>
</manifest>
write MainActiity
MainActivity {
...}
BootReceiver class
package com.example.BootReciever;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class BootReciever extends BroadcastReceiver {
#Override
public void onReceive(Context ctx, Intent arg1) {
Intent iMainActivity = new Intent(ctx, yourMainActivityClass);
iMainStartActivity.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ctx.startActivity(iMainActivity);
}
}
At a guess, I'd say it's probably because your manifest specifies .BootReceiver as the receiver, but based on your code the BootReceiver class is nested inside MainActivity. So you either need to move BootReceiver to a top-level class, or change your manifest to specify .MainActivity.BootReceiver as the receiver.
If that doesn't resolve it, please post your logcat so we can see what error is causing the crash.
Use this in the Manifest as receiver section:
<receiver
android:name=".BootReciever"
android:enabled="true"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
And take care of Broadcast Receiver class that should be not inner:
package com.example.BootReciever;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class BootReciever extends BroadcastReceiver {
#Override
public void onReceive(Context ctx, Intent arg1) {
Intent iMainActivity = new Intent(ctx, MainActivity.class);
iMainStartActivity.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ctx.startActivity(iMainActivity);
}
}
Your app starts so quick and doesn't let other important apps to start first I think you should add some delay in your app to start up. like this:
public class BootUpReceiver extends BroadcastReceiver {
#Override
public void onReceive(final Context context, Intent intent) {
// We can't wait on the main thread as it would be blocked if we wait for too long
new Thread(new Runnable() {
#Override
public void run() {
try {
// Lets wait some time before starting the service to be fair to other processes on startup
Thread.sleep(5000);
} catch (InterruptedException e) {
}
Intent myIntent = new Intent(context, MainActivity.class);
myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(myIntent);
}
}).start();
}

Categories

Resources