How to make the back of the activity to pass in front of the activity data?
Transfer data between the two have a lot of activity introduced in the jump with putExtras pressed into the data in the new activity in onCreate reception to most of the data says so.
I need a little not the same place, at the jump to a new activity after the original activity was still inside, the new activity in the finish after the return to the old use of activity, see back from onResume function, no need to jump through to complete, so the question is, how the new activity to old activity pass data?
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) -> Reply: In simple terms, an activity before destruction, transfer data up an activity, but this one activity in the end who is? It is not know.
Reply: You can not know how a Activity is so and so yet. A move to open a new Activity is certainly in the old Activity in startActivity (Intent in), right? If you want to pass in front of the Activity value. You can use startActivityForResult () This method opens a new Activity. Of course, if too true, as you said, I do not know who is an Activity trail. Then you can try using broadcast mode. Reply: New activity writes data files, the old activity read from file Reply: I do not know what you say is not startActivityForResult Reply: Use the application to share data, specific code online Reply: startActivityForResult easily Reply:
My new activity is selected in the file list to a file, select the file in the notification level, no matter what the level of activity.
Reply: Landlord, use startActivityForResult () to start a new activity, easy fly, when the new finish off, put the data in intent, setResult (int resultCode, Intent data), and then rewrite onActivityResult method in which the old activity:
The result is a data set inside in the new activity in the passed.
Reply:
Your list of files on which Activity is started. That he should be on a level Activity file list. Reply:
landlord, use startActivityForResult () to start a new activity, easy fly, when the new finish off, the data put intent in, setResult (int resultCode, Intent data), and then rewrite onActivityResult method in which the old activity:
The result is a data set inside in the new activity in the passed.
This should look! Reply:
landlord, use startActivityForResult () to start a new activity, easy fly, when the new finish off, the data put intent in, setResult (int resultCode, Intent data), and then rewrite onActivityResult method in which the old activity:
The result is a data set inside in the new activity in the passed.
This has helped Reply:
Landlord, use startActivityForResult () to start a new activity, easy fly, when the new finish off, put the data in intent, setResult (int resultCode, Intent data), and then rewrite onActivityResult method in which the old activity:
The result is a data set inside in the new activity in the passed.
This has helped
Or use this method to share data using application Reply: Yeah using data sharing, document, SQLITE can ah Reply: Useful. Are learning android. Reply: startActivityForResult positive solutions Reply: A:
Intent intent = new Intent (); intent.setClass (B.class); startActivityForResult (intent, request_code); @ Override protected void onActivityResult (int requestCode, int resultCode, Intent result) { if (resultCode! = RESULT_OK) { String a = result.getStringExtra (key); } }
B: Intent intent = new Intent (); intent.putStringExtra (key, value); setResult (RESULT_OK, intent); finish (); Reply: Broadcasting can indeed solve the problem by value, but can not have the time or do not try it Reply: if (resultCode! = RESULT_OK) { String a = result.getStringExtra (key); }
Correct
if (resultCode == RESULT_OK) { String a = result.getStringExtra (key); } Reply:
broadcast by value can indeed solve the problem, but can not do it or try it
Yes, ah, misuse of antibiotics to fight colds like broadcast.
Reply: Activity if you do not consider multiple instances, a static variable in the class Riga when global variables, you can visit any. ------------------- JAVA is no global variables, global variables are not even object, and sometimes even the name of the object can not know what is. However, the class definition is global. Static variables is to use a simple and effective way to solve a class of problems to solve global: For example, Andrews program has two windows, the main window class name MainActivity second window class name is SecondActivity know, But the object name is not known. Just to add a master class static variable can! public class MainActivity extends Activity { static String rs; / / static variable will be global, access methods: the class name of static variable name static int gloalV; / / global.................} In another class SecondActivity can access the global variables it: MainActivity.rs = "global variables, which could be visited!!!"; int v = MainActivity.gloalV; / / variable values to take over! Global variables with static variables do class has two advantages: 1 know the name of the class can access any static global variable, do not know the name of the class instance (also known as object name); (2) No matter how many objects the class static variable only one without an instance can be accessed; --------------- This approach will not have the side effects of soil do not know, experts hope the point that I am also a beginner Andrews two weeks.
Reply: I will tell you define global variables in the application to set and get the data, is very convenient, it does not have long-term storage, so why keep what file database. Reply: Discussion was very enthusiastic!
No comments:
Post a Comment