Menus

Thursday 9 May 2019

Android Activity



Calling one activity from another in android

Intent intent = new Intent(context, YourActivityClass.class);
startActivity(intent);
intent = new Intent(getApplicationContext(),CoursesActivity.class);
startActivity(intent);


How to start Activity in adapter?


holder.linearLayout.setOnClickListener(new View.OnClickListener(){
    @Override    public void onClick(View view) {

        Intent intent= new Intent(context, CoursedetailsActivity.class);
        
        context.startActivity(intent);

        
    }
});



How to Pass a Data from One Activity to Another in Android

* Passing data from one activity to other in android

Intent intent = new Intent(context, YourActivityClass.class);
intent.putExtra(KEY, <your value here>);
startActivity(intent);

holder.linearLayout.setOnClickListener(new View.OnClickListener(){
    @Override    public void onClick(View view) {

        Intent intent= new Intent(context, CoursedetailsActivity.class);
        intent.putExtra("courseid", listCourse.getCourseid());
        intent.putExtra("course",listCourse.getCourse());

        context.startActivity(intent);

    }
});


* Retrieving bundle data from android activity

Intent intent = getIntent();
if (null != intent) {
    String courseid= intent.getStringExtra("courseid");
    String course= intent.getStringExtra("course");
    Toast.makeText(this,courseid+"-"+course, Toast.LENGTH_LONG).show();
}



No comments:

Post a Comment