I have developed one application in which i need to register a user in SIP account as well as Chat account. To register the user i need pass through three classes: setting.java (sharedpreferences), sipchat.java (registeration to SIP account), xmppclient.java (to register in chat).
Now i am calling settings.class to register user in application in settings.java I am calling siochat.java and in sipchat.java i am calling xmppclient.java.
This is the way the user registers in application:
code:
Intent i = new Intent(Welcome_screen.this, Settings.class);
startActivity(i);
finish();
When using this application, it takes lots of time to register and it blinks as it passes through different activities.
So how do i call all three of these classes in a single activity? (Because it very weird that at the main screen the application blinks thrice.)
Thanks
I give you some solutions:
Use startActivityForResult(), pass through 3 activities and handle the result in your main activty.Example: http://rahulonblog.blogspot.com/2010/05/android-startactivityforresult-example.html
Change the content view of one activity. In this case, we have 3 views. Example: How to use view flipper with three layouts?
I don't understand why you need to start all these activities. Isn't it possible to just call static functions in the target activities?
Otherwise could you further explain why it's crucial that you start all these different activities and not just handle the functions in one activity?
Related
I am developing an Android Kotlin application which uses two different activities. In each one I have a button that allow me to move to the other one, to say, in Activity 1 I have a button that calls the follwing:
val intentActivity2 = Intent(this, Activity2::class.java)
startActivity(intentActivity2)
This launches correctly Activity2, which similarly inside it I have another button that calls the first activity to return to it:
val intentActivity1 = Intent(this, Activity1::class.java)
startActivity(intentActivity1)
The problem I have is that I want to have both activities running simultaneously (not needed to be shown at screen at the same time), and the issue right now is that every time I call the "startActivity(intent)" a new activity is created, loosing what I had in the previous one, so when I return to Activity1 everything is reset and the same when I go once again to Activity2. Both activities work fine and do their work, the problem is that I can't freely conmute between them.
Is there a way to have both activities at the same time or to not start a new activity everytime I want to change to the other one?
Thank you,
As someone just said you need ViewModel to retrieve your data after deleting/creating new activities. Maybe you can use fragments to do your things. Fragments are attached to activities and it is easier to use them instead of ViewModel.
I'm building my first Android app in Android Studio (with Java) and I need some help understanding how to pass data through multiple activities.
The setup of affected classes/activities is this:
MainActivity: Opens a dialog called AddDialog (by creating a new Instance of it).
AddDialog (extends AppCompatDialogFragment): A dialog that has some buttons. One of them launches a class called BarcodeScanActivity (using intent).
BarcodeScanActivity: Simple activity that scan QR codes.
I want to pass the list of QR codes scanned by BarcodeScanActivity (I store them in a String Array) to MainActivity in order to use them, although BarcodeScanActivity is launched from the dialog that gets destroyed once buttons are clicked. Because of that I'm unable to set some startActivityForResult on the dialog and chain the result (onActivityResult) back to the MainActivity.
Also since MainActivity launches the AddDialog by creating an instance, I can't set a startActivityForResult there too.
I have tried adding Intent.FLAG_ACTIVITY_FORWARD_RESULT while launching BarcodeScanActivity from AddDialog, hoping that the result from BarcodeScanActivity will be forwarded back to MainActivity where I have created an onActivityResult method since AddDialog gets destroyed, but I don't know if that is even supposed to work as AddDialog is "launched" by a new instance of it, and not by using an intent.
I have thought about using broadcasts as a last resort, although I read that they are insecure, unreliable and not supposed to be used for passing that kind of data.
Any help is highly appreciated! Thanks
I am trying to create an android app that has multiple "pages" ,
for example : you can choose any city in the world (e.g : Rome,Berlin,New york..), and by click on it you move to the specific city activity and get specific information, such as: country, nubmer of people.. etc (All the categories are the same, and the information changes for each city )
the specific information should be stored on mySQL database
I would like to ask - how can i implement this on an android application?
thanks!
You have to open a new Activity (CityActivity) adding the selected city to the Intent:
Intent cityIntent = new Intent(this, CityActivity.class);
cityIntent.putExtra("city", selectedCity);
startActivity(cityIntent);
Then in City activity you have to get the value that you sent via Intent:
String city = getIntent().getStringExtra("city");
Now you are able to get the information of the corresponding city and draw the information in a common view.
Use Fragment instead. just create a dynamic fragment that runs on one activity. its can handle almost anything an activity can handle.
A Fragment represents a behavior or a portion of user interface in an Activity. You can combine multiple fragments in a single activity to build a multi-pane UI and reuse a fragment in multiple activities. You can think of a fragment as a modular section of an activity, which has its own lifecycle, receives its own input events, and which you can add or remove while the activity is running (sort of like a "sub activity" that you can reuse in different activities).
Click Here on how to create Fragment
My app has 2 activities which have no way to reference eachother; what I would like is when Activity B is created, an event is triggered in Activity A (I'm trying to "finish()" Activity A)
Is there some kind of event handler that I can create in Activity A to listen for such a thing?
Only one activity at a time can be active which makes it impossible for one activity to send a message directly to another in real time.
From your description, I think you need to use one Activity that hosts multiple fragments. The fragments can "chat" to each other as much as you like and both can be active at the same time.
I am a newbie in Android and currently I am designing an application where I have faced a big problem with changing views. I have 3 classes, each one for a different screen. I use a button to change pages but it does not seem to work. Every time I move to the next screen, the variables methods etc of the 2nd screen are located in a different class. Can you please show me the simplest way to do this? Thank you.
Place each screen in different Activity. Start respective activities according to button presses. To pass data between activities use Intent.
Activity Reference
Intent Reference
Simple Example for Activities and Intents