logo
down
shadow

passing data from class to Activity via interface and modifying the UI


passing data from class to Activity via interface and modifying the UI

By : Pinni Smith
Date : November 19 2020, 03:01 PM
hop of those help? The problem is that your Bluetooth class doesn't run on the main/UI thread, as the activity does. In order to avoid race conditions, Android crashes the app to let you know that you're doing something wrong.
Fortunately, there is a simple way to fix this by using runOnUiThread(Runnable):
code :
public void receiveDataFromBluetoothConnection(String data) {
    runOnUiThread(() -> processIncomingBtMessage(data));
}
new Handler(Looper.getMainLooper()).post(() -> listener.receiveDataFromBluetoothConnection(data))


Share : facebook icon twitter icon
Passing data from activity to non-activity class without leaving current activity?

Passing data from activity to non-activity class without leaving current activity?


By : Pa_Ga
Date : March 29 2020, 07:55 AM
will help you The easiest solution will be to make a Global class and define all the variables which you want to share between different activities and classes there as 'static'. Then simply use Global.varName
Passing data from activity to service through interface

Passing data from activity to service through interface


By : user3206381
Date : March 29 2020, 07:55 AM
I wish did fix the issue. I am trying to pass data from an Android Activity to a Service. I am attempting to do so by calling a method within another class which contains an interface,this interface is implemented by the Service. ,
Passing data from activity to service through interface
code :
public static SubscribeHandler subscribeHandler;
subscribeHandler=this;
subscribeHandler.handleSubscribe("Message");
Passing data From Activity to Fragment using interface

Passing data From Activity to Fragment using interface


By : subhajeet
Date : March 29 2020, 07:55 AM
it helps some times I want to pass data from activity to bundle using interface no bundle. Please have a look at the code below: , Write this line of code after onCreate method.
code :
public void passVal(FragmentCommunicator fragmentCommunicator) {
    this.fragmentCommunicator = fragmentCommunicator;
}
public class MainActivity extends AppCompatActivity{

FragmentCommunicator fragmentCommunicator;
private Fragment fragment;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Button b = (Button) findViewById(R.id.button);

    fragment= new Fragment();

    //App is crasing for this line. Working fine by removing it
    //fragmentCommunicator = (FragmentCommunicator) getApplication();

    //fragmentCommunicator.passData("hello");
    getSupportFragmentManager().beginTransaction().replace(R.id.container ,fragment).commit();

    b.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            fragmentCommunicator.passData("Hello");

        }
    });

  }

   //Here is new method
   public void passVal(FragmentCommunicator fragmentCommunicator) {
       this.fragmentCommunicator = fragmentCommunicator;

   }
}
@Override 
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup  container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment, null);

((MainActivity) getActivity()).passVal(new FragmentCommunicator() {
       @Override
       public void passData(String name) {
           Toast.makeText(c, name, Toast.LENGTH_SHORT).show();
       }
   });
  return view;
}
Pass data from activity to a non-fragment/activity class without using an interface

Pass data from activity to a non-fragment/activity class without using an interface


By : Janine Gonzaga
Date : March 29 2020, 07:55 AM
wish of those help :) You can use multiple inheritance. To be able to make a class implement multiple interfaces we need can have something like this:
code :
public class MyClass extends MyOtherClass implements MyInterface1, MyInterface2, ... , MyInterfaceN {

    // Need to implement all interface methods here

}
Passing data from activity to interface

Passing data from activity to interface


By : user2989082
Date : March 29 2020, 07:55 AM
around this issue I'm trying to pass my data from one activity to an interface in kotlin. This value have to compose an url for getting a request json. Is it possible? How can I do it? , Try this:
code :
interface RequestApi {
    @GET("statistiche/{id}")
     fun getAllPosts(@Query("id") id:String): Call<ExchangeResponse>
 }
// receiving class
String id = intent.getStringExtra("Username")

private val retrofit = 
 Retrofit.Builder().baseUrl("http://x.x.x.x:xxxx/")
    .addConverterFactory(GsonConverterFactory.create())
    .build()
 private val postApi=retrofit.create(RequestApi::class.java)
 private val response = postApi.getAllPosts(id) // pass id here
Related Posts Related Posts :
  • Query id return type
  • Pass variable in API url in java .
  • Reading semicolon delimited csv
  • Get the workspace root
  • Native mmap error
  • hashmap and multiple txt files java
  • Kotlin: Access nested enum class from java
  • Google RateLimiter not Working for counter
  • Spring Boot Application Hanging When Running on Command Line
  • large amount of if else refactor
  • Unable to add xmlunit as dependancy in my pom
  • Scanner input needed twice, when only wanted once
  • How to interpret and translate kotlin code to java?
  • Firebase authentication: signInWithEmailAndPassword method dont respond at all
  • How Remove Recycler Separator/divider programmatically or using xml property
  • Not Able to Save Data Hibernate
  • Toolbar addView not working
  • Freeing memory wrapped with NewDirectByteBuffer
  • Synchronization with implicitwait() do not work, why?
  • Wrapper around Java primitive types
  • ClassNotFoundException: spark.Request when running from command line
  • Exception in Hibernate Configuration
  • How can I validate XML embedded in JSON using Citrus framework?
  • How is the String value passed to the updateText() method?
  • Memory efficient replace functions
  • Upload Photo with onActivityResult, but without Fullscreen capturing
  • Docker: Java 8 installation failing on Ubuntu
  • Java Netbeans Calculator performing wrong calculation
  • Nifi: Threads in nifi
  • While loop Int return inside the method completely dead
  • Checking if a user's entry is an integer using try catch statements
  • Forcing a subclass to provide an initialization method
  • calling a fuction and variables from another class in java
  • which versions of ssl and tls can we use for java 1.2
  • In spring-boot, is it possible to get properties without being a spring bean?
  • Java - Thread.join( ) does not release the lock
  • It reads the file but it is not printing it properly when it sends it to a new file?
  • Date picker Not Working on API 26
  • When does JPA persistence context end?
  • How to make Circle with Four Color in Java
  • java. inheritance/polymorphism, quiz error?
  • Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.io.Files.newReaderSupplier(Ljava/io/
  • How to convert a cURL call into a Java URLConnection call
  • Creating Substrings in a while loop
  • Java DateTimeFormatterBuilder with Verbose Time Zone
  • Memory leak using Stringbuilder in java
  • java string with English and Chinese text
  • How do I cast an array of doubles into an array of integers in Java?
  • Pair a bluetooth device in Android Studio
  • expected android.widget.textview but found java.lang.string
  • How to sort out by index(0) alphabelically or index(2) of the List<String> in the ArrayList<List<String>&
  • Creating a Drop Down Menu Bar in Java GUI
  • Java Regular expression - Pattern matching on a pipe-delimited string
  • How can i use blob storage from an azure function in Java
  • sorting numbers from a .txt doc into different category with if statements and loops
  • Creating a Search Button (Double cannot converted to String)
  • Spring Initializr Basic Project Won't Build
  • OpenCV error JAVA NETBEANS
  • How can I correctly map my classes (getting mappedBy reference an unknown target entity property)
  • RIght click JPopupMenu on JTabbedPane
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org