startActivity(new Intent("com.google.android.accessibility.talkback.tutorial.AccessibilityTutorialActivity"));
getting crash
Exception: No Activity found to handle Intent { act=com.google.android.accessibility.talkback.tutorial.AccessibilityTutorialActivity }
android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2064)
android.app.Instrumentation.execStartActivity(Instrumentation.java:1718)
android.app.Activity.startActivityForResult(Activity.java:5211)
androidx.activity.ComponentActivity.startActivityForResult(ComponentActivity.java:574)
android.app.Activity.startActivityForResult(Activity.java:5169)
androidx.activity.ComponentActivity.startActivityForResult(ComponentActivity.java:560)
android.app.Activity.startActivity(Activity.java:5540)
androidx.core.content.ContextCompat.startActivity(ContextCompat.java:251)
androidx.fragment.app.FragmentHostCallback.onStartActivityFromFragment(FragmentHostCallback.java:166)
androidx.fragment.app.Fragment.startActivity(Fragment.java:1377)
androidx.fragment.app.Fragment.startActivity(Fragment.java:1365)
i need to launch the talkback tutorial activity
The exception you're seeing suggests that the system cannot find the activity you're trying to launch. There are a few reasons why this might be happening.
First, make sure that the package name and activity name you're using is correct. It's possible that the name of the activity has changed in a recent update or you've made a typo.
Next, check that the activity is declared in the AndroidManifest.xml file for the application. Every activity that can be launched from outside the application needs to be declared in the manifest.
Finally, it's possible that the activity requires specific permission that your app does not have. Check the documentation for the activity to see if any permissions are required.
Related
We know that xml layout code gets parsed to java view object in setContentView call. But I was just curious to know when are the manifest properties (like windowSoftInputMode, screenOrientation etc) are applied to the activity. I mean what lifecycle method?
Any practical explanation is more than appreciated, TIA!
Well, I think manifest will get attached to the app in its installation period. like when we start installing an app , it will read its manifest file to check ;
where to install
What permissions to show
which activity is a launcher for the app
for more information:
https://developer.android.com/guide/topics/manifest/manifest-intro
Setting "exported=true" in the AndroidManifest allows that particular Activity to be launched by other applications. Does this also allow other applications to call ANY of the public methods inside that exported Activity manually? If so, how would the code to do that look like?
Please, read official documentation carefully:
This element sets whether the activity can be launched by components
of other applications — true if it can be, and false if not. If
false, the activity can be launched only by components of the same
application or applications with the same user ID. If you are using
intent filters, you should not set this element false. If you do so,
and an app tries to call the activity, system throws an
ActivityNotFoundException. Instead, you should prevent other apps from
calling the activity by not setting intent filters for it.
If you do not have intent filters, the default value for this element
is false. If you set the element true, the activity is accessible
to any app that knows its exact class name, but does not resolve when
the system tries to match an implicit intent.
This attribute is not the only way to limit an activity's exposure to
other applications. You can also use a permission to limit the
external entities that can invoke the activity (see the permission
attribute).
I came across a problem in a job interview that whether I can dynamically add a new activity to an Android application without releasing a new version of the app. And he told me that there exists certain mechanism that we could dynamically change the Activity to a new one, without registering in the AndroidManifest.xml file. I searched some documents, but did not found possible way to do this.
Can I start an Activity without registering in the AndroidManifest.xml file? And is it possible to dynamically modify the existing Activity?
Can I start an Activity without registering in the AndroidManifest.xml file?
No. I don't think you can start an activity that is not registered in the AndroidManifest.xml file. The manifest file keeps track of the activities that the app can use upon compiling/building the application. Any attempt to open an unregistered activity will result in an application crash.
And is it possible to dynamically modify the existing Activity?
As Bette Devine said, you can change the layout of the existing activity by calling setContentView(R.layout.new_layout); based on some user action (like a button press). However, calling setContentView more than once in your activity is a bad practice that people generally avoid doing. It is not recommended since you'll have to write code that would manage user interaction for the second layout. Imagine writing two activity codes in one java file. That would result in unnecessary clutter of code when you can just write them separately.
Yes it is possible to dynamically modify an existing one.
Here modification does not mean that you are changing the name of an activity but means that you are changing the content.
Just call the setContentView method of activity to give a new layout to the activiy and you whole activity now will be hosting a different content.
setContentView(R.layout.new_layout);
I want to open an activity without declaring it in an manifest file.
I don't know if it is possible or not.
What I actually want is to dynamically open an activity from my program using intents.
Can anyone help me if it is possible.
Not possible. Although I am unsure what you mean "dynamically open an activity".
See: http://developer.android.com/reference/android/app/Activity.html
Under Class Overview it states "To be of use with Context.startActivity(), all activity classes must have a corresponding declaration in their package's AndroidManifest.xml"
You can have an Activity in your package and not define it in the manifest, however you would not be able to start it successfully.
Your 'Dynamic' activity start is actually the normal way of starting an activity (as you have said in a comment to the answer of Matt M). Though you HAVE to add the Activities in manifest as Matt M said. In list view, clicking an activity will call a function that will start respective activity with startActivity() function.
I tried this very long, but since the Instrumentation class uses the IActivityTaskManager, which is a class of the internal API located at com.android.server.wm, that is not in the Activity classloader, I solved this by another method:
Using a subclass
I just made an Gist, with sample code.
GIST
I need to start android application not with Activity^ but with some controller class that will start some activity
Is it possible?
I'm not sure if I understand your question correctly, but an Android application is built up by four "components" as mentioned in the "Android Application Fundamentals", http://developer.android.com/guide/topics/fundamentals.html (no, you don't need all four of them make your application work).
The most common way of starting an application (and actually the only one I've been in touch with) is to define an Activity in your applications AndroidManifest.xml file as described on the link above. NOTE! that an Activity doesn't have to define a UI; you are not obligated to call the "setContentView()" function. Hence your "controller class" can extend Activity and be the very Activity you define as the start-up Activity in your manifest xml. You can then call "startActivity()" function with parameters to start any other Activity, whenever you see fit, from your controller class (this is also described in the link above).
Hope this helps.
Either create a GUI-less activity without calling setContentView() or use a BroadcastReceiver that accepts launcher intents (action=MAIN, cateogry=LAUNCHER). In Activity.onCreate or receivers callback method you can place logic which will invoke the actual activity of choice.