ajay dhadhal
ajay dhadhal

Reputation: 306

How to call activity of library module from app module

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

Answers (1)

AskNilesh
AskNilesh

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).

read from docs

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

Related Questions