Can we invoke one activity into another activity?
I Mean that i want to use one activity into another activity, Like class using create instance 开发者_如何学Pythonof that class. Is it Possible?
Well, I think you should use Intents to call an activity from another activity.
Call this from your Activity:
Intent in = new Intent(getApplicationContext(), NextActivity.class);
startActivity(in);
you can do it only by saying startActivity()
, no other go. you can't make an instance of Activity because , an Activity gets created when its onCreate()
method gets called, but when you say new MyActivity()
its default constructor is called and not its onCreate()
method (which Android OS will not accept). so always say startActivity()
or startActivityForResult()
which are handled by android OS
Write this code from where you want to run activity
Intent intent = new Intent(current_Activity_name.this,New_Activity_name.class);
startActivity(intent);
And add the following code into manifest file
<activity android:name=".New_activity_name" />
Well, since an Activity is a displayable-window, the appropriate concept would be that one Activity can be "launched" from another. This is how you achieve that:
Intent i = new Intent(CurrentActivity.this, NewActivity.class);
CurrentActivity.this.startActivity(i);
This code snippet can launch NewActivity
from any point in the CurrentActivity
code, for example, an 'OnClickListener'.
Yes, it is possible. This is achieved through Intents.
Intent intent = new Intent(this.getApplication(), TARGET_ACTIVITY_NAME.class);
//To add data use intent.putExtra(NAME,VALUE);
intent.setData(data.getData());
try
{
startActivity(intent); // This ll launch the TARGET_ACTIVITY_NAME
}
catch(Exception e)
{
}
For more information refer this link.
Shash
精彩评论