I am simply trying to navigate on Another Activity from my FragmentActivity having GoogleMap there. I have following code for InfoWindowClickListener
googleMap.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {
#Override
public void onInfoWindowClick(Marker marker) {
String distance[] = marker.getSnippet().split(" - ");
String distanceString = distance[0];
String idString = marker.getId();
String stationid = markershashmap.get(idString);
Toast.makeText(getApplicationContext(), "Clicked",
Toast.LENGTH_SHORT).show();
Intent dockitdetailsIntent = new Intent(
getApplicationContext(), AnotherActivity.class);
TabGroupActivity parentActivity = (TabGroupActivity) getParent();
dockitdetailsIntent.putExtra("stationId", stationid);
dockitdetailsIntent.putExtra("distance", distanceString);
parentActivity.startChildActivity("Activity Name",
dockitdetailsIntent);
}
});
But when I click the InfoWindow, my device hangs and then I have to force close the not responding app. When i use startActivity(dockitdetailsIntent) it works fine but Tab removes. But I want to use the Next Activity into the similar tabs. Please suggest me why my device hangs out and doesn't respond.
Create Handler and Put Intent logic into this like below:
mMap.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {
#Override
public void onInfoWindowClick(Marker m1) {
// TODO Auto-generated method stub
try{
String[] str2=str.split("contactID");
Message mesg = new Message();
Bundle b = new Bundle();
b.putString("contact_id", str2[1]);
mesg.setData(b);
handler.sendMessage(mesg);
}catch(Exception e){
e.printStackTrace();
}
}
});
And now create one handler like below:
private Handler handler = new Handler() {
#Override
public void handleMessage(Message msg) {
Bundle b = msg.getData();
Bundle b1 = new Bundle();
b1.putString("ContactID", b.getString("contact_id"));
b1.putBoolean("showBack", true);
Intent edit = new Intent(getParent(), ContactDetails2.class);
edit.putExtras(b1);
TabGroupActivity parentActivity = (TabGroupActivity) getParent();
parentActivity.startChildActivity("ContactDetails2", edit);
}
};
Try this. It's working in my case
Related
I am getting this error: Performing stop of activity that is not resumed LoginActivity. I have read the other threads about this error but I still can`t see what is the problem.
Here is my Logcat:
java.lang.RuntimeException: Performing stop of activity that is not resumed: {package/package.LoginActivity}
at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:3333)
at android.app.ActivityThread.handleStopActivity(ActivityThread.java:3420)
at android.app.ActivityThread.access$1200(ActivityThread.java:161)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1292)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5356)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
And my Activity:
public class LoginActivity extends Activity {
EditText edtMail,edtPass;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
Button regButton = (Button) findViewById(R.id.registerbtn);
Button logButton = (Button) findViewById(R.id.login);
final Context context = getApplicationContext();
edtMail = (EditText) findViewById(R.id.email);
edtPass = (EditText) findViewById(R.id.pword);
// testing if GooglePlayServices works//TODO
if(GooglePlayServicesUtil.isGooglePlayServicesAvailable(this) == ConnectionResult.SUCCESS )
System.out.println("Google PLAY SERVICES");
//getting specs for device //TODO
HashMap<String, String> specsHash = new HashMap<String, String>();
GetSpecs getSpecs = new GetSpecs(this);
specsHash = getSpecs.getAllSpecs();
for (Map.Entry<String,String> entry : specsHash.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
System.out.println(key + " = " + value);
}
//check device camera
boolean hasCamera = CheckDeviceCamera.isDeviceSupportCamera(context);
//check device GPS
boolean hasGPS = CheckDeviceGPS.isDeviceSupportGPS(context);
//if have details try to log the user in
if (new SharedPrefsMemo().getPrefs(context) == 1) {
DatabaseConnector databaseConnector = new DatabaseConnector(context);
//gasire: 0->nimic gasit, 1->gasit agent; 2->gasit asistent
int gasire = databaseConnector.loadInregistrare(Prefs.emailPref, Prefs.parolaPref);
if (gasire != 0) {
Intent myIntent = new Intent(LoginActivity.this, MainActivity.class);
myIntent.putExtra("tip", gasire);
startActivity(myIntent);
}
}
//register button
regButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(context, RegisterSplitActivity.class);
startActivity(intent);
}
});
logButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String password = edtPass.getText().toString();
String email = edtMail.getText().toString();
DatabaseConnector databaseConnector = new DatabaseConnector(context);
int gasire = databaseConnector.loadInregistrare(email, password);
if(gasire != 0 ) {
SharedPrefsMemo sharedPrefsMemo = new SharedPrefsMemo();
if(gasire == 1) {
sharedPrefsMemo.memoPrefs(GetObiecte.agent.email, GetObiecte.agent.parola, GetObiecte.agent.id,
context);
Intent myIntent = new Intent(LoginActivity.this, MainActivity.class);
myIntent.putExtra("tip", gasire);
startActivity(myIntent);
}
else
if(gasire == 2) {
sharedPrefsMemo.memoPrefs(GetObiecte.asistent.email, GetObiecte.asistent.parola,
GetObiecte.asistent.id, context);
Intent myIntent = new Intent(LoginActivity.this, MainActivity.class);
myIntent.putExtra("tip", gasire);
startActivity(myIntent);
}
}
else {
CharSequence text = "Date de logare gresite!";
int duration = Toast.LENGTH_LONG;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}
}
});
}
#Override
protected void onResume() {
super.onResume();
//activare GPS//TODO
LocationManager locationManager = (LocationManager)this.getSystemService(Context.LOCATION_SERVICE);
if(!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
//Ask the user to enable GPS
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Location Manager");
builder.setMessage("Activate GPS?");
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
//Launch settings, allowing user to make a change
Intent i = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(i);
}
});
builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
//No location service, no Activity
int duration = Toast.LENGTH_LONG;
Toast toast = Toast.makeText(LoginActivity.this, "Activate the GPS", duration);
toast.show();
finish();
}
});
builder.create().show();
}
}
}
I had the same problem and the answer by #sheetal solved my issue.
https://stackoverflow.com/a/23246159/4871489
The issue will still be there on all HighEnd phones with 4.4.2 and
above including NEXUS 5,Samsumg s4 since onResume gets called but
still it is in animation stage.So if you try to start a activity in
onResume the issue will replicate.
I created a handler to start my intent with a small delay and the issue disappeared.
Hope it helps
I have problem in my application.
I want to show user's profile, and I have two links in my app.
One link is via TextView, which run showUser(View v) method:
public void showUser(View v){
Intent i;
i=new Intent(getApplicationContext(), ShowProfile.class);
i.putExtra("id",user); // user is String with users ID
startActivity(i);
}
And the second link is in dialog, which user can open:
( I will post here whole method, but I'll highlight important part )
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder .setTitle(R.string.show_photo_show_rated_users_title)
.setNegativeButton("Close", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
});
ListView modeList = new ListView(this);
String[] stringArray = new String[ratedUsers.size()];
for ( int i=0 ; i<ratedUsers.size() ; i++ ){
stringArray[i] = ratedUsers.get(i).get("name");
}
ArrayAdapter<String> modeAdapter = new ArrayAdapter<String>(this, R.layout.dropdown_item_white, android.R.id.text1, stringArray);
modeList.setAdapter(modeAdapter);
modeList.setOnItemClickListener(new ListView.OnItemClickListener(){
/*********************** IMPORTANT PART *********************************/
#Override
public void onItemClick(AdapterView<?> parent, View arg1, int index,long arg3) {
Intent i;
i=new Intent(ShowPhotoDetails.this , ShowProfile.class);
i.putExtra("id",ratedUsers.get(index).get("id"));
/**** ratedUsers is ArrayList<HashMap<String,String>> ****/
startActivity(i);
}});
builder.setView(modeList);
final Dialog dialog = builder.create();
dialog.show();
}
And finally here's ShowProfile.class:
#Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.profile);
Intent i = getIntent();
try {
id = i.getStringExtra("id");
}catch(Exception e){
e.printStackTrace();
Toast.makeText(getBaseContext(), "Error loading intent", Toast.LENGTH_SHORT).show();
finish();
}
try{
Log.w("ID",id); //always give right number
new GetUserInformations().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, id);
/*
If I comments this asyncTask, there's no error at all, but if I run it, It
open debug View in Eclipse, says that "Source not found" and crashes...
No LogCat Output
*/
}catch(Exception e){
e.printStackTrace();
}
...
I wonder why in one case it run perfectly and in the other it crashes. As I wrote in code, there's no LogCat output for this crash. It don't even say Uncaught exception or something like this.
EDIT: I found out what gives me the error.
public class GetUserInformations extends AsyncTask<String,Void,Void>{
Map<String,Object> tmpUser;
#Override
protected void onPreExecute(){
tmpUser = new HashMap<String,Object>();
}
#Override
protected Void doInBackground(String... arg) {
try{
int u_id = Integer.parseInt(arg[0]);
tmpUser = myDb.getUser(u_id); // downloading info
}catch(Exception e){
e.printStackTrace();
}
return null;
}
#Override
protected void onPostExecute(Void arg){
if ( tmpUser != null ){
Log.w("LOG",""+tmpUser.get("name"));
name = (String) tmpUser.get("name");
fbId = (String) tmpUser.get("id");
email = (String) tmpUser.get("email");
country = (Integer) tmpUser.get("country");
userName.setText(name);
profilepic.setProfileId(fbId);
userSubscribe.setVisibility(View.VISIBLE);
}
else {
Toast.makeText(getBaseContext(), "Error", Toast.LENGTH_SHORT).show();
finish();
}
}
}
When I open activity for first time, everything downloads fine, but when I backPress and click on link to this Activity again, then it gives me NullPointerException.
Do you know why ?
In your onItemClick function, try to put :
i = new Intent(getApplicationContext(), ShowProfile.class);
instead of :
i = new Intent(ShowPhotoDetails.this, ShowProfile.class);
remove this:
new GetUserInformations().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, id);
and use :
if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.HONEYCOMB) {
new GetUserInformations().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, id);
}
else {
new GetUserInformations().execute(id);
}
What is the API level on which you are facing this problem. Try to run it on different levels, taking Honeycomb as a reference.
Need to check the same and apply execute or executeONExecutor like this:
if (currentApiVersion >=
android.os.Build.VERSION_CODES.HONEYCOMB) {
new YourAsynctask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} else {
new YourAsynctask().execute();
}
Check this asynctask-threading-regression-confirmed blog post
MainActivity.java
public class MainActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.anaekran);
Thread t = new Thread(new Runnable() {
public void run() {
String smsMsj = getIntent().getStringExtra("sms");
if(smsMsj != null){
Toast.makeText(getApplication(), smsMsj, 2).show();
}
try {
Thread.sleep(4000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
});
t.start();
}
}
SmsReceiver.java
public class SmsReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
Bundle mesaj = intent.getExtras();
SmsMessage[] smsMessage = null;
String msj = "";
if(mesaj!= null){
Object[] pdus = (Object[])mesaj.get("pdus");
smsMessage = new SmsMessage[pdus.length];
for(int i = 0; i < pdus.length; i++){
smsMessage[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
msj = smsMessage[i].getMessageBody();
}
Intent mIntent = new Intent(context, SmsReceiver.class);
mIntent.putExtra("sms", msj);
}
}
}
My receiver working correctly but i have one problem when message coming i want to show on my MainAcitivty toast, so i create mIntent in receiver class, and then im use putExtra method.
But not working, sory for my bad english and thank you :)
Perhaps using explicit Intent and starting it could help you, hm? :)
Intent mIntent = new Intent(context, MainActivity.class);
mIntent.putExtra("sms", msj);
context.startActivity(mIntent);
Your mistake is that you construct your new Intent with SmsReceiver.class (but you need to launch MainActivity) and that you do not start any activity with such an intent.
Edit 1: Also, pay attention - you are trying to run a toast inside your worker thread. This is not possible. Remove your anonymous Thread and move your toast code to your onCreate(Bundle):
protected void onCreate(Bundle saveState){
....
String smsMsj = getIntent().getStringExtra("sms");
if(smsMsj != null){
Toast.makeText(getApplication(), smsMsj, 2).show();
}
....
}
Edit 2: Moreover, your duration parameter in Toast.makeText(..) is set to 2. This does not correspond to any magic constant in Toast class. You have to use one of the constants: Toast.LENGTH_LONG or Toast.LENGTH_SHORT. So, rewrite your code to:
Toast.makeText(getApplication(), smsMsj, Toast.LENGTH_SHORT);
I'm trying to pass an array list containing Wi-Fi informations from a class that exdends from BroadcastReceiver to another class .I can pass a normal vriable between two classes with the getter. But i'm getting an empty array, because the onReceive methode is not executed .I would like to execute the onReceive methode in another class(but i can't instantiate it ) or to get the array created in the onReceive methode in another class with a getter (but i cant get the list).Please how can i get this array in the second class.
This is the WifiData class
public class WifiData extends BroadcastReceiver{
List<String[]> wifiValues = new ArrayList<String[]>();
WifiManager wifi;
Button enab;
String resultsString ;
String[] myStringArray;
int aa = 10;
int a=10 ;
List<String[]> getWifi (){
return wifiValues ;
}
#Override
public void onReceive(Context context, Intent intent) {
if(intent.getAction().equals(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)){
List<ScanResult> results = wifi.getScanResults();
resultsString = results.toString() ;
for(int i=0;i<results.size();i++){
Log.i("Wifi SSID",results.get(i).level+"");
wifiValues.add(new String[] { results.get(i).level +"" });
}
}
}
}
This is SalesStackedBarChart class that have to get the wifi infomation and create a chart :
public class SalesStackedBarChart extends AbstractDemoChart {
public Intent execute(Context context) {
WifiData wi = new WifiData ();
// values.add(new double[] {wi.getWifi() });
Log.i("aaaa",wi.getWifi()+"");
}
}
Thank you.
You are trying to show the data in graph using AChartEngine right?
Create a new activity and put the chart in that layout. Read here how to use the AChartEngine.
Now when you are passing the data from the first class(activity) to the second class(activity), you can pass the data using the intent. Add extra to the Intent using intent.putExtras().First create a bundle. In that bundle put the data using appropriate method like putSerializableExtra() or putParcelableExtra() and in the second class(activity) call getIntent and catch that intent in a temp variable.
From that you can retrieve the data using intent.getExtras().getSerializableExtra() etc. And you can load the data into AChartEngine data to be displayed as a graph.
This is a working solution :
Starting with WifiActivity activity ,wich will determin wifi scan list ,and send it to the TruitonAChartEngineActivity class.
WifiActivity activity
public class WifiActivity extends Activity {
/** Called when the activity is first created. */
WifiManager wifi;
Button enab;
String resultsString ;
String[] myStringArray;
int aa = 10;
//tableau pris à partir de http://www.radio-electronics.com/info/wireless/wi-fi/80211-channels-number-frequencies-bandwidth.php
int [ ] [ ] Center_Frequency_2 = { { 1,2,3,4,5,6,7,8,9,10,11,12,13,14 },
{ 2412, 2417, 2422, 2427, 2432,2437,2442,2447,2452 ,2457,2462,2467,2472,2484},
};
public class Receiver extends BroadcastReceiver{
#Override
public void onReceive(Context context, Intent intent) {
if(intent.getAction().equals(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)){
final List<ScanResult> results = wifi.getScanResults();
resultsString = results.toString() ;
Log.i("resultsString*****************",resultsString);
final String [ ] [ ] chanelRssi = new String [results.size()][2];
String[] tabResults = new String[results.size()];
for(int i=0;i<results.size();i++){
if (results.get(i).frequency /1000 == 2) {
for (int j =0;j<14;j++)
{ if (Center_Frequency_2[1][j] == results.get(i).frequency)
tabResults[i]=results.get(i).SSID +" (" + results.get(i).BSSID + ") \n"+ results.get(i).frequency +"\n"+ results.get(i).level +"\n"+ results.get(i).capabilities +"\n"+"canal "+Center_Frequency_2[0][j] ;
chanelRssi[i][0]=Center_Frequency_2[0][j]+"";
chanelRssi[i][1]=results.get(i).level +"";
}
}
}
Button send = (Button) findViewById(R.id.barChartButton);
send.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Log.i("click","click");
Toast.makeText(getApplicationContext(),
"Position :"+resultsString , Toast.LENGTH_LONG)
.show();
Intent intent1 = new Intent (getApplicationContext(),TruitonAChartEngineActivity.class);
Bundle bundleObject = new Bundle();
bundleObject.putSerializable("key", (Serializable) results);
intent1.putExtras(bundleObject);
startActivityForResult(intent1,0);
/* Intent intent1 = new Intent (getApplicationContext(),TruitonAChartEngineActivity.class);
startActivityForResult(intent1,0);*/
}
});
}
}
private void startActivities(Intent intent, int i) {
// TODO Auto-generated method stub
}
}
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_wifi);
ConnectivityManager cxMgr = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
wifi = (WifiManager)getSystemService(Context.WIFI_SERVICE);
Receiver receiver = new Receiver();
registerReceiver(receiver,new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
registerReceiver(receiver,new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
}
}
And the TruitonAChartEngineActivity class
public class TruitonAChartEngineActivity extends ActionBarActivity {
private static final int SERIES_NR = 2;
String message1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_truiton_achart_engine);
XYMultipleSeriesRenderer renderer = getTruitonBarRenderer();
myChartSettings(renderer);
Bundle v = getIntent().getExtras();
ArrayList<ScanResult> classObject = (ArrayList<ScanResult>) v.getSerializable("key");
// message1 = v.getString("message1");
/* Toast.makeText(getApplicationContext(),
"Position :" , Toast.LENGTH_LONG)
.show();*/
/* Toast.makeText(getApplicationContext(),
"Position classObject :"+classObject , Toast.LENGTH_LONG)
.show();*/
for(int index = 0; index < classObject.size(); index++){
String Object = classObject.get(index).level+"";
Toast.makeText(getApplicationContext(), "Id is :"+Object, Toast.LENGTH_SHORT).show();
}
Intent intent = ChartFactory.getBarChartIntent(this, getTruitonBarDataset(), renderer, Type.DEFAULT);
startActivity(intent);
}}
I am new on android und I try to transfer data between two Activities.
Eclipse tell me that the line:
Intent i = new Intent(this, PostDataActivity.class);
Constructor Intent is undefined. What can I do?
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnShowLocation = (Button) findViewById(R.id.ansehen);
// show location button click event
btnShowLocation.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
// create class object
gps = new GpsData(StartActivity.this);
// check if GPS enabled
if(gps.canGetLocation()){
double latitude = gps.getLatitude();
double longitude = gps.getLongitude();
String mlat = String.valueOf(latitude);
// \n is for new line
Intent i = new Intent(this, PostDataActivity.class);
i.putExtra("Value1", "This value one for ActivityTwo ");
You are trying to initialize your Intent from inside an OnClickListener. Hence, the this parameter you are passing to your constructor refers to the listener, and not your Activity.
To fix the problem use :
Intent i = new Intent(YourActivityName.this, PostDataActivity.class);
use
Intent i = new Intent(YourActivityName.this, PostDataActivity.class);