2016-08-07 5 views
0

내 Android 앱은 Yelp 검색 API를 사용합니다. 내 전화에 디버그 버전을 설치하면 정상적으로 작동하지만 서명 된 릴리스 버전을 빌드하면 yelp API 호출이 협조를 거부합니다. 실제 앱에서 foodButton, studyButton 또는 otherButton을 클릭하면 검색 함수가 호출되지만 명확하게 완료되지는 않습니다. 내 가정은 그Yelp API 검색이 Android 디버그 버전에서 작동하지만 출시 버전에서는 작동하지 않습니다.

while(!searchDone); 

이다. 그러나 나는 이유를 모른다.

public class SexyMapFragment extends FragmentActivity implements GoogleMap.OnInfoWindowLongClickListener,GoogleMap.OnInfoWindowClickListener, OnMapReadyCallback { 
    public static boolean backButton = false; 
    OnMapReadyCallback mapListener = this; 
    ArrayList<Business> businesses = new ArrayList<Business>(); 
    ArrayList<String> businessNames = new ArrayList<String>(); 
    ArrayList<String> textPhones = new ArrayList<String>(); 
    YelpAPIFactory apiFactory = new YelpAPIFactory("######", "######", "#####", "#####"); 
    YelpAPI yelpAPI = apiFactory.createAPI(); 
    String curTerm = ""; 
    boolean searchDone = false; 
    double topY; 
    double bottomY; 
    double leftX; 
    double rightX; 
    boolean dismissButton = false; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_sexy_map); 
     MobileAds.initialize(getApplicationContext(), "########"); 
     AdView mAdView = (AdView) findViewById(R.id.adMap); 
     AdRequest adRequest = new AdRequest.Builder().build(); 
     mAdView.loadAd(adRequest); 
     leftX = Integer.MAX_VALUE; 
     rightX = Integer.MIN_VALUE; 
     topY = Integer.MIN_VALUE; 
     bottomY = Integer.MAX_VALUE; 
     for (String name : MainActivity.checked) { 
      int index = in(MainActivity.friends,name); 
      LatLng ltlng = MainActivity.latlongs.get(index); 
      if (ltlng.latitude > topY) { 
       topY = ltlng.latitude; 
      } 
      if (ltlng.latitude < bottomY) { 
       bottomY = ltlng.latitude; 
      } 
      if (ltlng.longitude < leftX) { 
       leftX = ltlng.longitude; 
      } 
      if (ltlng.longitude > rightX) { 
       rightX = ltlng.longitude; 
      } 
     } 
     MainActivity.midLat = (topY + bottomY)/2.0; 
     MainActivity.midLong = (leftX + rightX)/2.0; 
     // Inflate the layout for this fragment 
     SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map); 
     mapFragment.getMapAsync(this); 
     findViewById(R.id.backMapButton).setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View view) { 
       backButton = true; 
       MainActivity.friends.clear(); 
       MainActivity.userPhones.clear(); 
       MainActivity.checked.clear(); 
       MainActivity.latlongs.clear(); 
       MainActivity.newUsers.clear(); 
       MainActivity.pending.clear(); 
       MainActivity.newUsers.clear(); 
       startActivity(new Intent(getApplicationContext(),MainActivity.class)); 
      } 
     }); 
     findViewById(R.id.foodButton).setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View view) { 
       curTerm = "food"; 
       SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map); 
       mapFragment.getMapAsync(mapListener); 
      } 
     }); 
     findViewById(R.id.studyButton).setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View view) { 
       curTerm = "study"; 
       SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map); 
       mapFragment.getMapAsync(mapListener); 
      } 
     }); 
     findViewById(R.id.otherButton).setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View view) { 
       findViewById(R.id.sexyMapLayout).setBackgroundColor(Color.rgb(60, 60, 60)); 
       findViewById(R.id.backMapButton).setAlpha(.1f); 
       findViewById(R.id.backMapButton).setClickable(false); 
       findViewById(R.id.foodButton).setAlpha(.1f); 
       findViewById(R.id.foodButton).setClickable(false); 
       findViewById(R.id.studyButton).setAlpha(.1f); 
       findViewById(R.id.studyButton).setClickable(false); 
       findViewById(R.id.otherButton).setAlpha(.1f); 
       findViewById(R.id.otherButton).setClickable(false); 
       LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
       final View tempView = layoutInflater.inflate(R.layout.search_map_popup, null); 
       final PopupWindow window = new PopupWindow(tempView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, true); 
       window.setFocusable(true); 
       window.setOnDismissListener(new PopupWindow.OnDismissListener() { 
        @Override 
        public void onDismiss() { 
         if (!dismissButton) { 
          window.setFocusable(true); 
          window.showAtLocation(tempView, Gravity.CENTER, 0, 0); 
         } 
         dismissButton = false; 
        } 
       }); 
       window.showAtLocation(tempView, Gravity.CENTER, 0, 0); 
       tempView.findViewById(R.id.popupCancelSearch).setOnClickListener(new View.OnClickListener() { 
        @Override 
        public void onClick(View view) { 
         findViewById(R.id.sexyMapLayout).setBackgroundColor(Color.rgb(255, 255, 255)); 
         findViewById(R.id.backMapButton).setAlpha(1f); 
         findViewById(R.id.backMapButton).setClickable(true); 
         findViewById(R.id.foodButton).setAlpha(1f); 
         findViewById(R.id.foodButton).setClickable(true); 
         findViewById(R.id.studyButton).setAlpha(1f); 
         findViewById(R.id.studyButton).setClickable(true); 
         findViewById(R.id.otherButton).setAlpha(1f); 
         findViewById(R.id.otherButton).setClickable(true); 
         dismissButton = true; 
         window.dismiss(); 
        } 
       }); 
       tempView.findViewById(R.id.popupDoSearch).setOnClickListener(new View.OnClickListener() { 
        @Override 
        public void onClick(View view) { 
         curTerm = ((EditText)tempView.findViewById(R.id.popupSearchTerm)).getText().toString(); 
         SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map); 
         mapFragment.getMapAsync(mapListener); 
         findViewById(R.id.sexyMapLayout).setBackgroundColor(Color.rgb(255, 255, 255)); 
         findViewById(R.id.backMapButton).setAlpha(1f); 
         findViewById(R.id.backMapButton).setClickable(true); 
         findViewById(R.id.foodButton).setAlpha(1f); 
         findViewById(R.id.foodButton).setClickable(true); 
         findViewById(R.id.studyButton).setAlpha(1f); 
         findViewById(R.id.studyButton).setClickable(true); 
         findViewById(R.id.otherButton).setAlpha(1f); 
         findViewById(R.id.otherButton).setClickable(true); 
         dismissButton = true; 
         window.dismiss(); 
        } 
       }); 
      } 
     }); 
    } 


    @Override 
    public void onMapReady(GoogleMap googleMap) { 
     googleMap.clear(); 
     googleMap.setOnInfoWindowClickListener(this); 
     for(String name : MainActivity.checked) { 
      int index = in(MainActivity.friends,name); 
      String curPhone = MainActivity.userPhones.get(index); 
      textPhones.add(curPhone); 
      googleMap.addMarker(new MarkerOptions().position(MainActivity.latlongs.get(index)).title(name).snippet(curPhone)); 
     } 
     googleMap.addMarker(new MarkerOptions().position(new LatLng(MainActivity.midLat, MainActivity.midLong)).title("MIDPOINT").icon(BitmapDescriptorFactory.fromBitmap(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher)))); 
     if(!curTerm.equals("")) { 
      businesses.clear(); 
      search(curTerm); 
      while (!searchDone) ; 
      searchDone = false; 
      for (Business business : businesses) { 
       googleMap.addMarker(new MarkerOptions().position(new LatLng(business.location().coordinate().latitude(), business.location().coordinate().longitude())).title(business.name()).snippet(getAddressFromName(business.name())).icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_YELLOW))); 
      } 
     } 
     googleMap.moveCamera(CameraUpdateFactory.newLatLngBounds(new LatLngBounds(new LatLng(bottomY,leftX),new LatLng(topY,rightX)),0)); 
     googleMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() { 
      @Override 
      public View getInfoWindow(Marker arg0) { 
       return null; 
      } 
      @Override 
      public View getInfoContents(Marker marker) { 
       View myContentView = null; 
       if(in(businessNames,marker.getTitle())!=-1) { 
        myContentView = getLayoutInflater().inflate(
         R.layout.info_item, null); 
        TextView tvTitle = ((TextView) myContentView 
         .findViewById(R.id.bizNameText)); 
        TextView tvSnippet = ((TextView) myContentView 
         .findViewById(R.id.snippetText)); 
        tvTitle.setText(marker.getTitle()); 
        tvSnippet.setText(marker.getSnippet()); 
       } 
       else { 
        myContentView = getLayoutInflater().inflate(R.layout.classic_item,null); 
        ((TextView)myContentView.findViewById(R.id.markerTitleWin)).setText(marker.getTitle()); 
        ((TextView)myContentView.findViewById(R.id.markerSnippetWin)).setText(marker.getSnippet()); 
       } 
       return myContentView; 
      } 
     }); 
     googleMap.setOnInfoWindowLongClickListener(this); 
    } 

    public void search(final String term) { 
     new Thread() { 
      public void run() { 
       Map<String, String> params = new HashMap<>(); 
       params.put("term",term); 
       params.put("limit", "10"); 
       CoordinateOptions coordinate = CoordinateOptions.builder().latitude(MainActivity.midLat).longitude(MainActivity.midLong).build(); 
       Call<SearchResponse> call = yelpAPI.search(coordinate, params); 
       Response<SearchResponse> response = null; 
       try { 
        response = call.execute(); 
       } catch (IOException e) { 
        e.printStackTrace(); 
       } 
       if(response==null) { 
        runOnUiThread(new Runnable() { 
         @Override 
         public void run() { 
          Toast.makeText(getApplicationContext(),"Nothing within 25 miles! Is your midpoint in the middle of the ocean?",Toast.LENGTH_LONG).show(); 
         } 
        }); 
        searchDone = true; 
        return; 
       } 
       ArrayList<Business> myBusinesses = response.body().businesses(); 
       businessNames = new ArrayList<String>(); 
       for(Business business : myBusinesses) { 
        businesses.add(business); 
        businessNames.add(business.name()); 
       } 
       searchDone=true; 
      } 
     }.start(); 
    } 
    public int in(ArrayList<String> arr, String check) { 
     for(int i = 0; i < arr.size(); i++) { 
      if(arr.get(i).equals(check)) { 
       return i; 
      } 
     } 
     return -1; 
    } 
} 

진심으로 사과드립니다. 이 모든 것이 정말 빨라야했기 때문에 품질이 상당히 stackoverflow-tier가 아니지만 누군가가 도움이되기를 바랍니다.

답변

0

마지막으로 알아 냈습니다.

while(!searchDone); 

while(!searchDone) { 
    try { 
     Thread.sleep(25); 
    }catch(Exception e){e.printStackTrace();} 
} 
에 : 나는 디버그 버전에서 생각, 안드로이드는 당신에게 내가 변경 무엇이든지 실행할 수있는 UI 스레드에서 좀 더 자유를 제공합니다