android - How to call a 'method' defined in another activity on click of a widget button? -


I know how to initiate an activity when clicking on the widget button while using the pending intent, but I I want to launch a specific way of that activity.

If you have to call any method in any other activity, then you are following the wrong design. Are there. You should not put all your code in activities alone

Why this is a bad option -
Because you have to call a method on this to the wanted. And how do you achieve an objective of activity? Unless you are storing an activity object in another (this is a very messy thing). Another problem in this approach is that your second activity has already been destroyed, so if you are relying on some UI elements of any other activity, you will not get any help. To stabilize the activities, very big bugs will open for you.

What is the option available? There are several options available for inter-activity mode call, but I rely on Sington. They are such classes that can have only one object that will be accessed steadily, so you do not have to store an object in the class anywhere, because the class stores only the object. This can go as follows -

  Public class AppManager {Private Static AppManager _instance = null; Public Fixed AppManager getInstance () {if (_instance == empty) _instance = new AppManager (); Return _instance; } Private App Manager () {} / Constructor is making the private, so any object can not be public; some method () {}}  

Therefore call > SomeMethod () In any form you will only need to call in your project

  AppManager.getInstance (). SomeMethod ();  

Then you can calculate all of it in you. You can store the object of the current activity in the manager category, or you can completely eliminate the functionality from the activity and get better control over your code. can do. And of course, you can have more than one singleton classes.

I usually work around 6-7 singleton managers in my project.

Comments

Popular posts from this blog

winforms - C# Form - Property Change -

java - Messages from .properties file do not display UTF-8 characters -

javascript - amcharts makechart not working -