android - pass value back to the same activity on a button click and refresh the page

I need to pass a value back to the same activity and refresh the activity to generate new data. Can anyone please provide me some ideas/guidance on how to do it? Thank you. I had try using intent to call the same activity but it doesn't work. Here is the code which i tried to use intent:

btn_next = (ImageButton) findViewById(R.id.btn_next);
        btn_next.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                page_counter = page_counter + 1;
                if (page_counter > 1){
                        btn_prev.setEnabled(true);
                }
                 Intent i = new Intent();
                 i.setClassName("sample.android.androidgallery","helloAndroid");
                 i.putExtra("page",wallpaper_page_counter); //to pass this activity's data to next
                 startActivity(i);
            }
        });


Asked by: Sophia962 | Posted: 25-01-2022






Answer 1

Intent intent = new Intent();
Bundle bundle = new Bundle();

bundle.putXXX(key,value);

intent.setClassName(MainActvity.this,MainActvity.class);
intent.putExtras(bundle);
startActivity(intent);

Answered by: Miller642 | Posted: 26-02-2022



Similar questions

callback - Service call backs to activity in android

I have a background service running and a client which interacts with the service. When the client requests for some operation, the service performs it and it should send the result back to the activity (client). I know how to invoke the service methods in activity and using call backs we can achieve what I want to do. But I am not able to understand the call back mechanism and code example provided in Api ...


Callback before Force Close of Android Activity?

I'd like to have some emergency cleanup code execute just before my app crashes. I tried using onDestroy(),, onFinal() and finalize() to no avail. Is this possible in an Android Activity?


android - NewBie: How do I pass a callback to another activity

I have a simple activity (Activity1) which will create a callback using 'ActionCallback'. I am executing this callback from Activity1 but the results appear after some time due to network delays, I need to show result of callBack on another view which is Activity2 (extends ListActivity). I dont want to wait in Activity1 (for user experience) for the callback to complete and then send to Activity2 using Intent.putEx...


Service callback to Activity in Android

I have an abstract of my GPSTracker. It returns the location of the user. It's works. public class GPSTracker extends Service implements LocationListener { public GPSTracker(Context context) { this.mContext = context; getLocation(); } public Location getLocation() { //GET LOCATION CODE return location; } So, I call this service in my MainActivity using this code:


android - How to callback an Activity in onAttach with Otto?

I am working on an app which uses the NavigationDrawer. Different fragments are placed into the content view of the MainActivity whenever a menu item in the drawer is selected. To inform the MainActivity that a Fragment successfully attached the following callback is executed:


Android Service Callback method to Activity

I have a Activity and a Service. I am using bindService to get the Binder object which gives my activity access to the service. So I am able to execute commands on the service easily. What I need is a way to have the service communicate back to the activity. Is the best way to handle this to make calls directly from my activity to the service via the service instance returned from the binder. Then use a local broadcas...


Android - passing callback from activity to service

I have a situation where an activity needs to start 2 services, one is bound, one is not. The bound will return a Ibinder to the activity. But the activity needs to some how provide a callback to both the services, i.e. both services must be able to call some methods in a nested class in the activity. What is the best way to do this ? Should I use broadcast from services, and then call the desired API from...


java - Android: How do you pass a callback to an activity?

I am creating a library. It creates an activity, starts it, and finishes it after a button is pressed. After the button is pressed, I'd like to execute some client code through an interface. That is, users of this library pass in an implementation, and I simply execute it. The analogous iOS code would be: MyViewController *vc = [[MyViewController alloc] init]; vc.callOnComplete = ......


java - Callback From Activity on Cordova

I have an activity Called 'Signature' and i call it from CordovaPlugin; Plugin.java public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { Intent i = new Intent(context, Signature.class); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); cordova.startActivityForResult(this,i,90); } public void onActivityResult(int reques...


java - How to do async OkHttp request in another class and then callback to activity

I want to move my OkHttp async request to a separate class as I use it multiple times in multiple activities in my application. Is this possible? I've read a lot about it but can't find a solution for me. MainActivity.java public void mainActivityMethod(String JSONData) { // Handle JSONData string } MyClass.java public void doRequest() { OkHttpClient okHtt...


callback - Service call backs to activity in android

I have a background service running and a client which interacts with the service. When the client requests for some operation, the service performs it and it should send the result back to the activity (client). I know how to invoke the service methods in activity and using call backs we can achieve what I want to do. But I am not able to understand the call back mechanism and code example provided in Api ...


java - Android GPS Callback off UI Thread

I'm having trouble getting the GPS's onLocationChanged to run on a different thread. I understand how to manage UI thread when I'm calling a function but with the GPS, I don't actively call the function. My intent is to have a light flash every time the GPS receives a reading. I have put this function in a Runnable. I passed this function to a class that implements LocationListener. Then in the main class, I start...


Callback before Force Close of Android Activity?

I'd like to have some emergency cleanup code execute just before my app crashes. I tried using onDestroy(),, onFinal() and finalize() to no avail. Is this possible in an Android Activity?


android service callback

I have made an application based on the android API's remote service application wich uses callbacks to notify the main activity for changes, the app works fine passing just a single int value from the remote service back to the activity. The problem is that I would like to pass some Strings and not an int back in order to update the activiti's UI, how can I do that? I have thought of returning an object but there is lack...


android - Network Service needs to return a callback

I have a Networking service that i want to use as a Service. It's a local Service since it's not valid anymore once the application process is dead and no Other applications need to access it.(or should...). I was pondering if to use the IBinder interface with local reference to the class and decided not to, for the moment. I have the following issues: if the service dies, and i know it can du...


android - Timer with callback

Info I have a class SensorClass that manages some sensors. I have an interface with method A(). I have a tester class TestClass that implements the interface with method A() and passes this implementation to SensorClass. TestClass extends Activity. Objective Every X seconds I need to call the implemented method of the interface s...


android - Oauth Callback not found after allowing the app on Twitter

Hey. I am developing an application using the Twitter4j api. In order to allow the application and get an access token, I launch the browser with the callback parameters which I had set in the manifest file. <data android:scheme="scheme" android:host="authenticatorapp"></data> After allowing the application, the browser calls the following and fails with a not found message. ...


callback - How I can call back in Android using OAuth for Twitter?

From last 5 days I am search for a best working pice of code for twitter in android using OAuth... I found a lot. But not a single 1 is running perfectly. Any how i get some code. Its working but I have a problem. I am wondring what I have to write in String callBack = "?" so that my android browser redirect me to my application back instead of staying there after authentication.. If I am not using a CallBack and use


android - CallBack not working on Galaxy Tab, but does work on all other devices

I'm testing my app out on my brand new Galaxy Tab and I encountered something strange. I have Twitter integration in my app. What it basically does is open a WebView and use Oauth to autheticate. After that it sends a CallBack back to my app with the secret token and there I use it for tweeting purposes. You can get more info about how I do this here:


Should I use a callback or some kind of event in Android?

I am just starting to learn Android Development. I have a method that loads an external XML file, and parses the data. How do I tell the caller that the data is parsed and ready? Should I and a callback argument to the method? Or should the caller register to listen to some kind of event, that I can fire when the data is ready? A code example or links would be great.






Still can't find your answer? Check out these communities...



Android Google Support | Android Community | Android Community (Facebook) | Dev.io Android



top