How can I create an Intent from class in a package

2019-08-31 03:58发布

Not sure how to explain this,hope you understand me.. Here is the problem :

I have a few packages in my app and I'm doing this :

Intent intent = new Intent(view.getContext(), com.example.app.Lol.class); 
startActivity(intent);

and his code is in class which is in package : com.example.anotherone

It's not possible as I saw, that's why I'm asking..what I have to do, so I can be able to create an Intent like the example above.

Thanks anyway!

3条回答
叼着烟拽天下
2楼-- · 2019-08-31 04:41

Make sure you are importing the class you want

import com.example.anotherone.Classname;

and pass Classname.class in your intent,

Intent intent = new Intent(view.getContext(), Classname.class);

And that your Manifest is updated with the correct name for the activity (com.example.anotherone.Classname).

查看更多
对你真心纯属浪费
3楼-- · 2019-08-31 04:45

1.At first import the class you want.
2.pass the class name with intent.
For example:

import package.otherclassname.yourclassname;
Intent intent=new Intent(view.getContext(),yourclassname.class);
查看更多
成全新的幸福
4楼-- · 2019-08-31 05:01

If you want to start an activity from another application, you can do it by specifying the intent action. When you define the activity you want to start in its application Manifest file, you can set it's <action/> tag inside <intent-filter/> to whatever action you want. Then to start this activity from another application call

Intent intent = new Intent("your-action-name");
startActivity(intent);

Your application will be the only to answer on this action request and it will open. Hope this helps.

查看更多
登录 后发表回答