App crashing when starts an activity with intent - android

The app crashes in Android Studio when a button is clicked to reach the another activity through intent
public void next(View view) {
Toast.makeText(getApplicationContext()," Next called " , Toast.LENGTH_SHORT).show();
startActivity(new Intent(getApplicationContext(),SecondActivity.class));
}
The error I am getting from logcat is
Caused by: android.content.ActivityNotFoundException: Unable to find
explicit activity class
{com.example.utkarsh.internalstorage/com.example.utkarsh.internalstorage.SecondActivity};
have you declared this activity in your AndroidManifest.xml?

specify activity in your android manifest file
<activity android:name="SecondActivity"> </activity>

The issue is, the SecondActivity Activity wasn't added to the AndroidManifest.xml. Once you add that as an application node, it will work properly.
<activity android:name="com.example.utkarsh.internalstorage.SecondActivity" />

Error message is clear, define your activity in your manifest

Related

"RuntimeException: Could not launch activity...Unable to resolve activity for Intent" when running Jetpack Compose UI tests with createComposeRule

Running tests with createComposeRule and hitting a stack trace like (irrelevant parts omitted):
java.lang.RuntimeException: Could not launch activity
at androidx.test.runner.MonitoringInstrumentation.startActivitySync(MonitoringInstrumentation.java:495)
...
Caused by: java.lang.RuntimeException: Unable to resolve activity for: Intent { act=android.intent.action.MAIN flg=0x14000000 cmp=my.app.package.name.here/android.app.Activity }
...
The OP question is about the use of createComposeRule() which doesn't require a custom activity (it uses ComposeActivity under the hood).
In this case you need to include this below in your gradle file:
debugImplementation("androidx.compose.ui:ui-test-manifest:1.0.0-beta05")
If you take a look at the contents of that package, it's simply an AndroidManifest.xml with an <activity/> entry for androidx.activity.ComponentActivity.
You need declare an Activity with name android.app.Activity in your AndroidManifest.xml for the Compose UI tests to use to host the content. Add the following within your <application> tag:
<activity android:name="android.app.Activity" android:theme="#style/your_app_theme_here"/>
substituting your_app_theme_here with a theme that exists in your app.
You need to add
<activity android:name="androidx.activity.ComponentActivity" />
to your manifest.

Beginning an application while no starting activity set

I would like to launch my application and check the connectivity state in application's onCreate method then decide which activity to start! I know that I could finish() a default MAIN/LAUNCHER activity before to setLayout while starting another if it's relevant but that seems messy to me!
So, I would like to know if it is possible to start an application whose doesn't manifest an activity with action.MAIN / category.LAUNCHER? I tried this way but it doesn't work! I mean the application seems to start but no activity is shown!
(This is not a sample from my real code, I'm not at home right now! Some arguments and stuff may be missing but I think you get the point!)
public class MyApp extends Application {
onCreate() {
Intent intent = new Intent(this, MyActivity.class);
intent.setFlags(Intent.NEW_TASK);
this.startActivity(intent);
}
}
Also, the first activity of my application may be an AlertDialog and I'm wondering if I can start one while no activity is started or if I'm forced to set an activity's theme with #android:style/Theme.Dialog?
I tried the same as for the above example but same result : logcat saying application alive while no printing at all...
Tell me if I'm not clear enough and in which way! I'm not an english speaker and I'm not used to ask in forums!
You will have to go this way:
public class MainActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.some_empty_or_loading_view); //optional probably, not sure
//TODO: check whatever you want
if(condition) {
startActivity(this, SomeActivity.class);
} else {
startActivity(this, AnotherActivity.class);
}
finish();
}
}
Specify Your App's Launcher Activity
When the user selects your app icon from the Home screen, the system calls the onCreate() method for the Activity in your app that you've declared to be the "launcher" (or "main") activity. This is the activity that serves as the main entry point to your app's user interface.
You can define which activity to use as the main activity in the Android manifest file, AndroidManifest.xml, which is at the root of your project directory.
The main activity for your app must be declared in the manifest with an that includes the MAIN action and LAUNCHER category. For example:
<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>
Note: When you create a new Android project with the Android SDK tools, the default project files include an Activity class that's declared in the manifest with this filter.
If either the MAIN action or LAUNCHER category are not declared for one of your activities, then your app icon will not appear in the Home screen's list of app

Crash when launching a new Activity from a Fragment

I get an error when launching an activity from a fragment, using an intent.
Intent intent = new Intent(this.getActivity(),FormActivity.class);
intent.putExtra("Horas",hours);
intent.putExtra("Minutos",minutes);
intent.putExtra("Segundos",seconds);
intent.putExtra("Fecha",date);
intent.putExtra("Hora",time);
startActivity(intent);
LogCat:
android.content.ActivityNotFoundException: Unable to find explicit activity class
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1719)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1491)
at android.app.Activity.startActivityForResult(Activity.java:3436)
at android.app.Activity.startActivityForResult(Activity.java:3393)
at android.support.v4.app.FragmentActivity.startActivityFromFragment(FragmentActivity.java:848)
at android.support.v4.app.Fragment.startActivity(Fragment.java:878)
at es.timetrack.app.InActivityPageFragment.onClick(InActivityPageFragment.java:148)
Declare the Activity you are starting in the Manifest .xml file:
<activity
android:name="your.package.FormActivity"
android:label="FormActivity" />
Some additional information:
The App Manifest
There you can see the structure of the manifest.xml file and what it is used for.
In addition to you not declaring your Activity in the manifest file, your application might crash due to unhandled exceptions in the onCreate(...) method of your FormActivity.

Unable to start activity - YouTubeStandalonePlayer

I am trying to use YouTubeStandalonePlayer from https://developers.google.com/youtube/android/player/reference/com/google/android/youtube/player/YouTubeStandalonePlayer
With this code inside onCreate():
Intent intent = YouTubeStandalonePlayer.createVideoIntent(this, DeveloperKey.DEVELOPER_KEY, VIDEO_ID);
startActivity(intent);
But application fails with error.
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.youtubestandalone/com.example.youtubestandalone.MainActivity}: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.google.android.youtube.api.StandalonePlayerActivity.START (has extras) }
How to fix this?
Add this line to your AndroidManifest.xml
<activity
android:name="com.google.android.youtube.api.StandalonePlayerActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
/>
Check if you have include the jar file in your project. Make sure you have done the follow steps.
Right Click your project
Select Properties
Select Java Build Path
Go to Order and Export Tab
Tick YouTubeAndroidPlayerApi
Good luck!

Explicit Intent error

I want to new activity when i click an image.
I already write activity android:name=.openPdf in manifestfile.
but it shows me an error:-
"android.content.ActivityNotFoundException: Unable to find explicit activity class {Parsing.this/openPdf.class}; have you declared this activity in your AndroidManifest.xml?
"
Code ::
iv1.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
// Toast.makeText(getApplicationContext(), "hello",Toast.LENGTH_SHORT).show();
Intent pdf=new Intent(Parsing.this,openPdf.class);
startActivity(pdf);
}
});
Please make sure like your activity which you are launching is in the same package, then and then you can write like android:name=.openPdf else need to use the full class name with package.
Actually you havnt register activity in your manifest file so to overcome that
add activity tag and its Name in your Manifest file,
like...
<activity android:name=".openPdf" /> // "." works as a package name
Instead of Parsing.this use getApplicationContext(); This may work. And instead of adding android:name=".openPdf" manually. Browse it in manifest application tag.
Cheers!!!

Categories

Resources