0

I am an android newbie also not very affluent with java. I am trying to to understand MobiStego source code.

Hence the following is a part of the project code I fail to understand fully.

Please help....

private void initClickListner()
    {
        Button buttonEncode = (Button) findViewById(R.id.ButtonEncode);
        buttonEncode.setOnClickListener(new Button.OnClickListener()
        {
            public void onClick(View v) {

                 Intent intent = new Intent();

                  intent.setComponent(new ComponentName(EncodeActivity.class.getPackage().getName(),
                          EncodeActivity.class.getCanonicalName()));
                  startActivity(intent);
            }
        }
        );
egor92
  • 5
  • 5

2 Answers2

0

1-initClickListner() is a method that who is made herself. User method. Like;

public void myfunction(){ ..... ..... }

2-setcomponent and class.getpackage are kind of intent component. I suppose u know intent mechanism in android. This intent type for different package names in application. For example u have com.axample.yourappname and com.example.yourappname2 packages. This intent, cross intent for different package activities. If u want to call activity of second package from activity of first package u can call above function.

MehmetF
  • 61
  • 1
  • 14
  • thanks a lot, but please tell me how to figure out the number of packages in my android project and btw what does the term getCanonicalName mean....? – egor92 Feb 10 '14 at 14:28
  • Default u have 1 package in your app. Under your project u must see brown bundle. This is your package. If u right click on your project in eclipse and add new package u can see your second package. getCanonicalName; ClassDemo c = new ClassDemo(); Class cls = c.getClass(); // returns the canonical name of the underlying class if it exists System.out.println("Class = " + cls.getCanonicalName()); – MehmetF Feb 10 '14 at 14:34
  • Mark this question for apply dude. – MehmetF Feb 11 '14 at 18:55
0

I would like to extend MehmetF's answer only. As he said, initClickListner() is only a user-defined method name, nothing special than that.
ComponentName acts as an identifier for a specific application component, this component may be an activity or a service.
class.getPackage().getName() is used to get the package name of the specified Class name before it.
These 2 links will also help you to have a clear idea:

EDIT: class.getCanonicalName() is the name that is used in an import statement and uniquely identifies the class. Well, i think you need to see these differences to understand clearly.

Community
  • 1
  • 1
ridoy
  • 6,274
  • 2
  • 29
  • 60
  • If you think that solves your problem then mark it as answer so that it can help others also. – ridoy Feb 11 '14 at 13:23