Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Being relatively new to Android, I guess I didn't word my question properly. Here is what I am trying to do. Generally when you start a new intent, you finish the old activity by using class.this.finish() . But I want to finish a different class, not the current class. Let's say I have an activity with a button. Clicking the button would take me to a second activity. Now clicking another button takes me to a third activity and simultaneously finishes the first activity. Probably finish is the keyword here and not kill.
You could have a BroadcastReceiver registered in first activity, and send a broadcast from the third activity. Then in onReceive() method of the receiver finish() the activity.
However, re-thinking the design could be a better solution.
This is a question that doesn't have a straightforward answer. Killing activities is not a good design pattern for Android, so my first thought is "don't do this." Of course, that's not very helpful.
We may be able to help if you describe what you're trying to do. We may be able to suggest an alternative that doesn't requiring killing an Activity, or allows one Activity to finish another in a more "approved" manner.
Sometimes the answer to a problem is to suggest a different problem. Like the robot banging against the wall, the problem is not cutting through the wall, but learning how to turn and go on.
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I want to fetch data and show it in grid view which is in Fragment but I am getting error.But when I tried to implement same thing in Activity it is working fine why it is happening so?..
Why things get different when implemented in Activity and Fragment?
Can Anyone tell what is to be changed and where we can get stuck?
Thanks.
Slow down. Fragments are tough to grasp and implement when you just got started. To get a better understanding work yourself through this guide. Also make sure you experiment with this example project. Both link to the official Android Developers site.
EDIT: To get the basic picture, make sure you understand the Activity lifecycle and how this lifecycle connects to the Fragment lifecycle. To save yourself from frustration over getting stuck, watch this video and concentrate on the image at 6:10. If you want your Activity and Fragment objects to communicate smoothly, you will need to know when and where you can make method calls and callbacks. There's plenty of other useful material, just keep on searching.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
Can I make an object of Android Activity like this:
Activity activity = new Activity();
If no, then why?
And what are the problems that I may face due to this?
Can I make an object of Android Activity like Activity activity = new Activity();
Will it compile? Yes. Will it work at runtime? Probably not.
If no then why?
Because the activity will not have been set up properly. It will not appear on the screen, will not go through the lifecycle methods, will not be connected to the rest of Android, etc.
What are the problems that I may face due to this?
A never-ending series of crashes.
To show an activity, call startActivity().
Technically you can do this. But remember, you will have an instance of an Activity which is not known to Android. So you won't be able to do much with it and it won't be shown either. You might need such instance if you write tests for your application.
In your application's code you should rather never do it. Android will create an instance of Activity when you start an by calling following method.
Context.startActivity(new Intent(this, MyActivityClass.class));
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I have written code to get all the list of installed apps in the device and pick one to run. Now but I want that when an item is clicked the item should get added to another list which would be used in another activity.
I have ActivityA which lists all the installed apps. When an user clicks an app in ActivityA it should be added to arraylist which is used in ActivityB. i.e. ActivityB will just have the apps that are selected by user in ActivityA. How can I do that?
Also this ActivityB is in another app so what should I use to store the arraylist? SQLiteDatabase or is there something much simpler than that?
Thank you.
If I understand your question correctly, you essentially want to store information across applications. The best way to do this would be through a ContentProvider
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions must demonstrate a minimal understanding of the problem being solved. Tell us what you've tried to do, why it didn't work, and how it should work. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am new at android and I am trying to make an android app which takes from you the time and sends a message to user at that time. Can someone tell me the steps to follow so I can make this app.
This is actually pretty simple. One way to do this (may not be the simplist but would give you good experience with a bunch of the android framework:
Register a BroadcastReceiver
Gather the information (message, destination, time) from the user using UI elements.
Send an intent to the BroadcastReciever with the time specified.
Send the sms from the BroadcastReceiver, using SmsManager.
This would also give you a lot of opportunity to add to this app, you can learn to use Content Providers to keep track of the current 'Pending Messages' and give the user an option to view and edit them.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have developed my first android application i.e. CHECKERS ,which is working perfectly for two players, now some users of my app wants me to add a single player mode as well.
Can you guys plz help me how can I fulfill this demand,How to code for this.Your help will be highly respected.
I used canvas drawing in my app and my class extends SurfaceView implements runnable.
Thanks!
I am willing to help you with ideas:
I assume you already have a project, which works with two players. If you want to achieve 1-player mode without too much pain, you should follow the ideas described below:
Create a ComputerPlayer class, inherit it from your Player class.
Override methods, such as move to occur automatically (at first, start with random moves, don't get delved deep into the AI logic just yet, because first you want to support automatic moves, and then you will want to focus on AI strategies)
Where you send/receive the moves support sending/receiving moves from ComputerPlayer as well (you will not really send a message to the network, but your current project probably uses terminology as "send", "receive")
Test, test and test.
When everything is well, choose an AI strategy, implement it and you are done with the upgrade.