Accessing data in Android activites - java

I am new in using java and android. I've read about the android application life cycle and other android programming basics. I need to create an application with 5 activities and will communicate with Bluetooth reader and smart card:
Home - In this activity the app should check if the the Bluetooth of the phone is enabled or not. This will be first activity which will display the 4 buttons below.
Begin - This will ask the user to present a smart card and will check if the card is valid or not.
Register - this will create a new account and the information will be saved in the smart card connected to the Bluetooth reader.
4.Select device - This will display the scanned/available Bluetooth reader in a List view. Once the user select an item, the application will go back to the Home page and the name of the Bluetooth device selected will be displayed in the Home page.
Device Info - This will display some information of the selected Bluetooth device.
Now, how should I implement this using listeners. From what I have read, other activity that is not visible to the user may be killed by the system to free up some memory space thus, the resources of that activity will be gone also. Is that correct? I want to implement this without having to create an instance of a reader class on each activity (if this is possible). I also thinking of creating a Parcelable class so that I can pass the reader class to other activities including the values that are needed by other activities.
Any help will be highly appreciated. Thanks in advance.

This is a pretty heavily contested subject among the Android community, but have you considered using Fragments?
If you are just getting started with Android, I think this approach would be entirely worthwhile. Although the Activity/Fragment life-cycle is pretty complex, if you are serious about wanting to learn Android, dealing with Fragments (at least for now) is almost unavoidable.
Even if you end up in the Anti-Fragment group, at least you'll have your own personal experiences from which you can come up with your own opinions.
I personally think that this approach will make your life a bit easier. If you do a Google search for "communicating between fragments" you will find a ton of examples to help get you started. When I was first getting starting, I watched a lot of the videos by slidenerd.
I just checked and he has a 3 part series about communicating between fragments, and the next video after the third one is about saving/maintaining the state of your fragments.
After you get a bit more acclimated with the basics, then I would suggest ditching the listeners and learning/using RxJava.
Hope this helps, don't hesitate to come back with more questions.

Related

Splitting display in Android for different Apps

I'm creating middleware app for android which in main think will allow people create games based on blocks easily. The idea comes from Siftables (sifteo cubes) - I'm creating Android version :)
The idea was to make middleware which contains GUI to display blocks and board, and allow players to move blocks. Middleware is connected with game (another app), which count score and do another basic things. And here comes my question. I want to split display into two parts - one for middleware GUI and second for game e.g. displaying score.
I found Fragments, but everywhere it was used in one application. Is it possible to display two fragments from differen apps at one time?
Thanks, for help :)
Is it possible to display two fragments from differen apps at one time?
No, sorry.
You can use RemoteViews — what app widgets and custom notifications use — to pass bits of UI from one app to another, though RemoteViews are limited.
You could create your own RemoteViews-like system, marshalling instructions for how to build a UI and pass events, then use that between your apps.
On Android 7.0+, the user could enter split-screen mode, showing two activities side-by-side, and you might leverage that for what you are seeking.
You should take a look here:
https://developer.android.com/guide/topics/ui/multi-window.html
But as CommonsWare mentioned, it is only from Android 7.0 officially.
With same hacks, you can use it it lower Android versions too, but root necessary.
Or you have to use manufacturer specific APIs, if it is supported, like on Samsung devices:
http://developer.samsung.com/s-pen-sdk/technical-docs/Designing-For-The-Galaxy-Note-Creating-Multi-Window-Apps
So, I think the best option would be splitting middleware GUI for GUI and part for game, so game would send data to middleware and it would display it.

How to make my App modular?

Hi and thanks for your attention.
I have an Android App (Java) whose code is growing (and eventually will need to grow more and more).
So I have to face the fact that I have make it somehow modular to make it manageable.
So I am here to ask some advice on how to go about it.
Basically the Apps consists of 2 screens, lets' call them A and B.
The App starts with screen A, which is a quiz, if the user responds correctly the screen B is displayed, showing the results; if the user wants to go on and take another quiz the App switches again to screen A, and so on in an infinite loop.
Please can you give me some advice no how to make this app more modular, to avoid all the code written in 'onCreate()'.
In particular how could I implement communication between the modules: how the Quiz module would communicate to the main and ask to switch the screen from A to B; how would the actions performed on screen B would communicate again to the main and ask to switch again to A.
I know it is a very open question, I am looking for some guidance, any suggestion very much appreciated.
For communications between screens, you could use sending messages or better Observer pattern. If you change something on screen B, it call screen A method, that do something.
Generally, for your problem, look at design patterns. Some of them could be usefull and they are widely supported in Java.
I am not very familiar with Android, but iOS has notifications (similar to triggers). Maybe something like that exist also for Android.

communication project using android

i'm doin my project in 8th sem telecomm engineering, and i'm plannin to create a DUPLEX(not confident whether it'd be full or half) communication app using bluetooth and wifi as channels,something more advanced than a simple walkie talkie, and i was wondering if this is possible for a one man army??? also i was wondering if it is possible to do so with android versions 2.2 and above... can i just program the bluetooth settings in app in such a way, that, it doesn't pop up for user permission to accept a voice message from the calling party??
and is there a possibility for creating multiple channels(one for Forward Voice Channel and one for Reverse Voice Channel) using bluetooth or wifi?? here's a list of few knowledge i possess:
JAVA: basics, done some gui in desktops, know some imp classes,only SE6...
WIRELESS COMMUNICATION: learning it this semester, stuff like how base station accepts incoming mobile station request and redirects it to dest, mostly 1g in our portions...
OPERATING SYSTEMS: general, looking forward to learning android and linux os...
C,C++,DSP,and SOME ELECTRONICS...
oh, and iwoul like to implement these well within 7 months duration...
people please ENLIGTHEN me with your wisdom and references to useful websites ASAP...
my THANKS AND WISHES to thee...:)
The first big problem i see is that on using wifi for this, and as i understood it is some sort of (advanced) walkie-talkie app with no rooter inbetween the communicating phones, you have to implement adhoc-wlan on your android device, which is not supported by android, so you will need a rooted device for that, and the implementation of adhoc-wlan on android is definitve possible (have a look at this code: http://code.google.com/p/android-wifi-tether/) but nothing easy (i have done it myself for an university project).
And you asked if you can avoid the permission pop-up for an incoming message, but on an android phone activating your bluetooth or pairing it with an other device will always ask for permission from the user.
I cant help about the multiple channels you were asking for.
As Answer to your big Question: "is it possible for a one man army?" i would say generelly yes, but it depends on how much other stuff you have to do. Since you were writing this is an project for university, i dont know if this is your only project and you can invest a lot of time in it. If so i guess it is possible, but it will be an quite big project and you should be willing to work yourself relativly deep into networking stuff.
On google.Code you can find some projects similar (at least the wifi part) to what you think about to do, take a look at them...

Is it possible to remotely view a user's device?

I want to make an app where it allows the user to give remote access to viewing their phone (first-person view of user using the phone). Kind of like how tech support can sometimes see what you're doing on your computer to help you with problems. Think "remote desktop for phone" is what I'd like to do.
Does anyone know if this would be possible?
My current idea to do this is screen scraping - somehow take a screenshot of the user's phone (like how DDMS does) every millisecond or something. This seems terribly inefficient though, and again I don't know if it's possible.
Note - the "receiver" of this first-person phone view can be a computer or website or whatever, along as they connect remotely.
It would be possible: extremely difficult, but possible, to implement an Android activity that uses a FrameLayout and hosts another Activity. You could then fetch the image buffer of the FrameLayout as shown here and you'd then have to feed that into a video encoder and stream the output of the encoder to a remote server, but that might work.
I actually wanted to create something like that as well...
First of all, it will only work on rooted devices, since access to the "screenshot" (framebuffer) is allowed only to rooted devices.
Now as to reading events from the controlling device - that's easy... The hard part would be to generate these events on the controlled device. But I'm absolutely sure it's possible for rooted devices, as I saw some similar program for Windows which controls the connected device (can't remember its name).
Anyway, the reason I stopped thinking about this app is its complexity and the fact only Rooted devices could be controlled.
Hope this helps

Possible to 'layer' Android applications?

I know this in general is beyond the scope of SO, but I am looking for some basic yes/no info to see if it is even feasible to proceed... I am thinking about building and Android 'note-taking/annotation' app that runs 'over' other installed Android apps, such as the web browser for example.
Essentially, while the user is browsing, my app would be running in the bg as a service, and then they could activate it which would then essentially intercept user inputs and translate those on a transparent canvas over the web browser into lines, shapes, etc. The user could then take a screen-cap of their marking with the underlying web page, which would be stored to the sd card.
This is a very good idea and a great question, but sadly, I do not believe it is possible.
The way Android is designed only one Activity can have focus at a time, while a Service could run in the background, the user would not be able to interact with it. The user can only interact with the currently active Activity.
Again, love the idea, but it is sadly not supported.
You might be able to achieve this with the WindowManager service. You can then use that to call addView() with a view of type TYPE_SYSTEM_ALERT, or possibly TYPE_SYSTEM_OVERLAY (but see the notes in the documentation about taking input focus).
I haven't tried it myself, but I've seen several apps (often dictionary apps that translate whatever words you tap on) that do overlays, and they always seem to require the SYSTEM_ALERT_WINDOW permission.

Categories

Resources