Making a basic redirect function

  • Replies:2
  • OpenNot stickiedUnanswered
  • Forum posts: 2

Jun 13, 2016 2:56:24 AM via Website

im trying to make a function to make directing with intent more smooth.

so instead of this

public void gotoPage(View view){
Intent intent = new Intent(this, MainActivity.class);

i want it something like this

protected void gotopg(String tgtlnk){
Intent intent = new Intent(this, MainActivity.class);

calling this way....gotopg(MainActivity) so when i call it its a simply 1 line to go to another activity.

I am new to this and java was never my strong suit but i do have php experience.

i want to be able to call this function send a variable which would be the target to go to.

i also dont understand why there is a View view. could someone elaborate this a bit more. im really confused.

  • Forum posts: 256

Jun 15, 2016 11:52:19 AM via Website

Hi Derek,

public void gotoPage(View view)

View-class parameter is used when you set gotoPage() as onClick method for some View element of layout (such as button, image, text, etc) for example:


In this case variable "view" will content the Button-object with id "btn1"

If you don't use gotoPage() as onClick method, you can set any other parameters.