简体   繁体   English

烧烤在另一个班级的活动中创建的吐司不起作用

[英]Roasting of toasts created in an activity that is a call from another class does not work

From one class I am creating an activity defined in another class. 从一个类中,我正在创建另一个类中定义的活动。 This class has void methods, they do not return anything but if they print toast. 此类具有void方法,但它们不会返回任何内容,但会打印吐司。 Specifically they are gps values, the idea is to create the intent and print the values ​​for the moment but it does not work 具体来说,它们是gps值,其想法是创建意图并暂时打印值,但它不起作用

The method from where I create the "GPsLocation" activity is "TornosAdapter" and has the following code 我从中创建“ GPsLocation”活动的方法是“ TornosAdapter”,并具有以下代码

 holder.torn_button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Toast toast = Toast.makeText(c, "Puerta:" + t.getNumero_puerta() + "\nGeolocation: " + t.getGeolocation(), Toast.LENGTH_LONG);
            //localizacion gps
            Log.d(TAG,"Pasa a crear el intent");
            //Here I create GpsLocation
            Intent intent = new Intent(v.getContext(), GpsLocation.class);
            toast.show();
        }
    });

And the class where I define the GpsLocation activity with void methods and that do not work are these 我用无效方法定义GpsLocation活动的类是无效的

    package com.gpasport.controlaccesos.controlaccesos;
import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.Toast;
import android.util.Log;


/**
 * Created by asanchez on 26/09/2017.
 */

public class GpsLocation extends Activity {

    private static final String TAG = MainActivity.class.getSimpleName();
    /**
     * Called when the activity is first created.
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        Log.d(TAG,"GpsLocation creating bundle activity");
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.main);
        LocationManager milocManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        LocationListener milocListener = new MiLocationListener();
        milocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, milocListener);
    }

    public class MiLocationListener implements LocationListener {
        public void onLocationChanged(Location loc) {
            loc.getLatitude();
            loc.getLongitude();
            /*Prueba para imprimir la latiud por log*/
            Log.i(TAG,Double.toString(loc.getLatitude()));
            String coordenadas = "Mis coordenadas son: " + "Latitud = " + loc.getLatitude() + "Longitud = " + loc.getLongitude();
            Toast.makeText(getApplicationContext(), coordenadas, Toast.LENGTH_LONG).show();
        }

        public void onProviderDisabled(String provider) {
            Toast.makeText(getApplicationContext(), "Gps Desactivado", Toast.LENGTH_SHORT).show();
        }

        public void onProviderEnabled(String provider) {
            Toast.makeText(getApplicationContext(), "Gps Activo", Toast.LENGTH_SHORT).show();
        }

        public void onStatusChanged(String provider, int status, Bundle extras) {
        }
    }
}

I would like to know why it is failing, I am sure it is a problem of creating the activity. 我想知道为什么失败,我确定这是创建活动的问题。 I have been looking at examples that work but the only difference is the communication with parameters with activities that in this 我一直在看一些可行的示例,但唯一的区别是在此活动中通过参数进行通信

You never start the GpsLocation Activity . 您永远不会启动GpsLocation Activity You do this: 你做这个:

        //Here I create GpsLocation
        Intent intent = new Intent(v.getContext(), GpsLocation.class);
        toast.show();

but this does not start GpsLocation . 但这不会启动GpsLocation You need to call startActivity(intent) after creating the Intent . 创建Intent后,您需要调用startActivity(intent)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM