There are many ways to start another activity. The most of the overloading methods requires you to pass a context.
But when using componentName to launch an activity using
public Intent setComponent (ComponentName component)
and this constructor for ComponentName
ComponentName(String pkg, String cls)
You see above, I am able to launch an activity WITHOUT using any Context argument
But it must use some "context" somehow internally, am I right? If so, which context? Application one or the activity one? Does this mean that every time I use this two methods (above), I do not need to worry about memory leak becuase I am not passing any context around??
Thanks
Just use these following two lines, so you can launch any installed application whose package name is known: Intent launchIntent = getPackageManager(). getLaunchIntentForPackage("com. example.
To start an activity, use the method startActivity(intent) . This method is defined on the Context object which Activity extends. The following code demonstrates how you can start another activity via an intent. # Start the activity connect to the # specified class Intent i = new Intent(this, ActivityTwo.
An intent filter is an expression in an app's manifest file that specifies the type of intents that the component would like to receive. For instance, by declaring an intent filter for an activity, you make it possible for other apps to directly start your activity with a certain kind of intent.
You don't have to worry about memory leaks in either case, but it's good that you're keeping an eye on where you're passing Context objects. Intent simply uses the Context parameter to look up your package name when you use the Intent(Context, Class)
constructor or setClass(Context, Class)
method. They're just convenience methods.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With