I have a app with a main activity, a graph activity an a Bluetooth ConnectListenerImpl.
The main activity search for a bluetooth device and the Bluetooth ConnectListenerImpl connect with the device and send data Message to the main activity with a Handler.
And that the main activity display the data.
Now i want to display the data in the graph activity which is a child of the main activity.
The start of the child activity.
bGrafiekShow = true;
Intent intent = null;
intent = new Intent(MainActivity.this, GraphActivity.class);
startActivity(intent);
Now is my question how can i do that and what is the best way?
Little extra information. The main activity put the data from the Bluetooth in a other class this class make some calculation. After the calculation is finish the main activity put the result on the screen.
The Bluetooth device sends the data every one second.
Now I want the calculated data plot in a time graph in a child activity. But how can i send the data to the child activity.
You can pass data thought Activities
as map of data presented like Bundle
with putExtra() methods of Intent
with Serializable or Parceable interface.
Or you can use ResultReceiver class. You can combine it with IntentService instead of Handler. In Service you will do your work and any update will be sent into ResultReceiver and receiver will update UI.
Put the device ID in your intent or in a bundle.
intent.putExtra("DEVICE_ID", deviceId);
When starting your second activity, retrieve device Id and connect your "child" second activity to the bluetooth via ConnectListenerImpl.
Related
I'm having a slightly different purpose, but, I think I'm putting it wrong as no one from multiple forums is able to answer it. The original question is here: Pass URL data from AppLink to WebView
Basically, suppose I'm creating a web browser app with a splash screen and I want to accept the URL intents from other apps, receive them in my splash screen, pass them on to my WebView activity and load it there, how can I do that?
For example, if a user has my app installed, and he/she taps https://www.google.com/ as a link in some app, how can I load the URL in my app after showing my splash screen? I think, the intent receiver will be in the splash screen activity, and the WebView is in another activity. So, basically, I want to receive the URL in my splash screen activity and then, pass it on to my WebView. How to achieve this?
I think what youre trying to do is to recieve data from other apps
That way, you can recieve data in a Splash Screen Activity and then show it in a Web View Activity
You can do this through putExtra method.
You can use intents, which are messages sent between activities. In an intent you can put all sort of data, String, int, etc.
In your case, in Splash Screen(say SplashActivity), before going to next activity(say MainActivity), you need to store a String message this way :
Intent intent = new Intent(SplashActivity.this, MainActivity.class);
intent.putExtra("message", message);
startActivity(intent);
In MainActivity, in onCreate(), you can get the String message by retrieving a Bundle (which contains all the messages sent by the calling activity) and call getString() on it :
Bundle bundle = getIntent().getExtras();
String message = bundle.getString("message");
Then you can use message variable as url.:
Hope this helps !
I have an ongoing activity but once I receive a broadcast from the android.net.conn.CONNECTIVITY_CHANGE I wish to display to the users that there is no internet connection from an already active fragment activity
Container app = (Container) context.getApplicationContext();
app.recreate();
But the above code does not work in the onreceive method in my broadcast intent reciever and cause a can not cast android app to fragment activity Container. How do I fix this?
I wish to display to the users that there is no internet connection
from an already active fragment activity
Try having a "BaseFragmentActivity" that has a broadcast receiver member that does this. And each FragmentActivity in your app should extend it.
I have a class that listens to SMS broadcast and, it then open an activity in the same application to display the message. This is part of a larger project.
Since the broadcast class does not extend the activity class, calling an Activity with intent requires that I flag it with Intent.FLAG_ACTIVITY_NEW_TASK.
Now the Intent has an extra (the SMS message and some parameters as a single string) which i want to send with the intent. All went well but the Extras are not sent with the intent.
Here are my code
From the broadcast class
//After getting the message into String S and doing some process
Intent inte = new Intent(context.getApplicationContext(), StartApp.class);
inte.putExtra("messageAsString", S.toString()); //Where S is declared somewhere
inte.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(inte);
From the activity recieving the Intent in the onCreate() method
if(getIntent().hasExtra("messageAsString")) {
String message = getIntent().getStringExtra("messageAsString").toString();
Toast toast = Toast.makeText(this, "Received SMS: " + message , Toast.LENGTH_LONG);
toast.show();
}
The application may have already running, the home button has been pressed. Either way, what I want to achieve is that as the registered reciever receives the message, I want to start an activity automatically and pass the message and its meta data to it.
I know I'm missing something somewhere but will appreciate your swift help
You also need to handle onNewIntent(), which may be called if the activity already exists and startActivity() brings an existing instance back to the foreground. Your extra is probably in there.
I have an Android app with a working push notification set up. It works currently like this:
User gets a push notification
When the user taps on the push notification, he is taken to a screen which has the list of all the notifications. It is basically a list view which has all the notifications.
Now, want to implement the following:
a. When a new notification comes to the user, it has to be displayed on the list view, irrespective of whether a user taps on it.
b. I have to indicate the number of notifications that user has received on the app icon. For instance, if you get a message in whats app, it displays the number of messages on the app icon.
Could anybody let me know what is the best possible way to implement these functionality? If anybody could point me to tutorials/references, it would be very helpful.
Thanks!
a. Launch an activity from the receiver(GCM/C2DM receiver) when the push notification arrives
// Your C2DM receiver (for GCM check the Android Documentation)
public void onReceive(final Context context, final Intent intent)
{
if (intent.getAction().equals(com.google.android.c2dm.intent.RECEIVE))
{
//start your list view activity of notifications
Intent i = new Intent();
i.setClassName("com.test", "com.test.NotificationsActivity");
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
b. Check this.
I always get bundle value null when I pass data from activity to broadcast receiver.
My receiver will start on boot up.
This is the code in my activity class
Intent intent= new Intent();
intent.setAction("android.intent.action.BOOT_COMPLETED");
intent.putExtra("test", "test");
sendBroadcast(intent);
This is the code in my receiver class:
String testValue = intent.getStringExtra("test");
Your code in activity will never be called upon booting up. System invokes onReceive() with its own intent. You can check this by putting some logs in activity code - this log will not be printed in logcat.