Reputation: 306
i want to call Activity
of library module from the app module.but app crash.following is my code
MainActivity.java
public class MainActivity extends AppCompatActivity
{
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent intent = new Intent("com.example.main.mainactivity");
startActivity(intent);
}
}
please help me.
Upvotes: 1
Views: 450
Reputation: 69671
The
Intent
constructor takes two parameters:
Intent intent = new Intent(Contecxt,Class);
1. A Context as its first parameter (this is used because the Activity class is a subclass of Context)
2. The Class of the app component to which the system should deliver the Intent (in this case, the activity that should be started).
use this
Intent intent = new Intent(this,MainActivity.class);
startActivity(intent);
instead of this
Intent intent = new Intent("com.example.main.mainactivity");
startActivity(intent);
Upvotes: 1