我有非常奇怪的Lein的行为:它不断加载未使用的旧代码。
public class Activity_Recognized_Service extends IntentService implements GoogleApiClient.OnConnectionFailedListener, GoogleApiClient.ConnectionCallbacks, LocationListener {
/**
* Creates an IntentService. Invoked by your subclass's constructor.
*
* @param name Used to name the worker thread, important only for debugging.
*/
public static final String TAG = "###RECOGNISED SRVCE###";
Timer timer;
GoogleApiClient LocationAPIclient;
LocationRequest mLocationRequest;
Location mCurrentLocation;
boolean startLocationFirst=true;
public Activity_Recognized_Service() {
super("Activity_Recognized_Service");
}
public Activity_Recognized_Service(String name) {
super(name);
}
@Override
protected void onHandleIntent(@Nullable Intent intent) {
Log.d(TAG, "On Handle Intent");
if (ActivityRecognitionResult.hasResult(intent)) {
Log.d(TAG, "ActivityRecognition Has Result");
ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);
handleDetectedActivities(result.getProbableActivities());
Navigation_Drawer nav = new Navigation_Drawer();
nav.UserMovementResult(result);
}
}
@Override
public void onCreate() {
super.onCreate();
Log.d(TAG,"On Create Calling");
if (LocationAPIclient == null) {
Log.d(TAG, "Location API is NULL Value Of This ");
LocationAPIclient = new GoogleApiClient.Builder(this)
.addApi(LocationServices.API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
}
}
private void handleDetectedActivities(List<DetectedActivity> probableActivities) {
for (DetectedActivity activity : probableActivities) {
switch (activity.getType()) {
case DetectedActivity.IN_VEHICLE:
Log.d(TAG, "In Vehicle " + activity.getConfidence());
if (activity.getConfidence() >= 75) {
//Send Notification To User
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setContentText("In Vehicle");
builder.setSmallIcon(R.drawable.elaxer_x);
builder.setContentTitle("Elaxer");
NotificationManagerCompat.from(this).notify(0, builder.build());
requestLocatonSetting(10*60*1000,8*60*1000,LocationRequest.PRIORITY_HIGH_ACCURACY); //5 hours= hours * 60 min*60 sec* 1000 milliseconds
//requestLocatonSetting(6*60*1000,6*60*1000,LocationRequest.PRIORITY_HIGH_ACCURACY); //TEST
LocationAPIclient.connect();
if (startLocationFirst){
Log.d(TAG,"Start Location Update For Car");
}
}
break;
case DetectedActivity.ON_BICYCLE:
Log.d(TAG, "On Bicycle " + activity.getConfidence());
if (activity.getConfidence() >= 75) {
//Send Notification To User
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setContentText("On Bicycle");
builder.setSmallIcon(R.drawable.elaxer_x);
builder.setContentTitle("Elaxer");
NotificationManagerCompat.from(this).notify(0, builder.build());
requestLocatonSetting(7*60*1000,5*60*1000,LocationRequest.PRIORITY_HIGH_ACCURACY); //5 hours= hours * 60 min*60 sec* 1000 milliseconds
//requestLocatonSetting(6*60*1000,6*60*1000,LocationRequest.PRIORITY_HIGH_ACCURACY); //TEST
LocationAPIclient.connect();
}
break;
case DetectedActivity.ON_FOOT:
Log.d(TAG, "On Foot " + activity.getConfidence());
if (activity.getConfidence() >= 75) {
//Send Notification To User
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setContentText("On Foot");
builder.setSmallIcon(R.drawable.elaxer_x);
builder.setContentTitle("Elaxer");
NotificationManagerCompat.from(this).notify(0, builder.build());
}
break;
case DetectedActivity.RUNNING:
Log.d(TAG, "On Running " + activity.getConfidence());
if (activity.getConfidence() >= 75) {
//Send Notification To User
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setContentText("Running");
builder.setSmallIcon(R.drawable.elaxer_x);
builder.setContentTitle("Elaxer");
NotificationManagerCompat.from(this).notify(0, builder.build());
requestLocatonSetting(3*60*1000,2*60*1000,LocationRequest.PRIORITY_HIGH_ACCURACY); //5 hours= hours * 60 min*60 sec* 1000 milliseconds
//requestLocatonSetting(6*60*1000,6*60*1000,LocationRequest.PRIORITY_HIGH_ACCURACY); //TEST
LocationAPIclient.connect();
}
break;
case DetectedActivity.STILL:
Log.d(TAG, "On Still " + activity.getConfidence());
if (activity.getConfidence() >= 75) {
//Send Notification To User
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setContentText("Still");
builder.setSmallIcon(R.drawable.elaxer_x);
builder.setContentTitle("Elaxer");
NotificationManagerCompat.from(this).notify(0, builder.build());
requestLocatonSetting(5*60*60*1000,3*60*60*1000,LocationRequest.PRIORITY_HIGH_ACCURACY); //5 hours= hours * 60 min*60 sec* 1000 milliseconds
// requestLocatonSetting(3*60*1000,2*60*1000,LocationRequest.PRIORITY_HIGH_ACCURACY); //TEST
LocationAPIclient.connect();
}
break;
case DetectedActivity.TILTING:
Log.d(TAG, "On Tilting " + activity.getConfidence());
if (activity.getConfidence() >= 75) {
//Send Notification To User
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setContentText("Tilting");
builder.setSmallIcon(R.drawable.elaxer_x);
builder.setContentTitle("Elaxer");
NotificationManagerCompat.from(this).notify(0, builder.build());
requestLocatonSetting(3*60*1000,2*60*1000,LocationRequest.PRIORITY_HIGH_ACCURACY); //5 hours= hours * 60 min*60 sec* 1000 milliseconds
//requestLocatonSetting(6*60*1000,6*60*1000,LocationRequest.PRIORITY_HIGH_ACCURACY); //TEST
LocationAPIclient.connect();
}
break;
case DetectedActivity.WALKING:
Log.d(TAG, "On Walking " + activity.getConfidence());
if (activity.getConfidence() >= 75) {
//Send Notification To User
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setContentText("Let's Walk");
builder.setSmallIcon(R.drawable.elaxer_x);
builder.setContentTitle("Elaxer");
NotificationManagerCompat.from(this).notify(0, builder.build());
requestLocatonSetting(3*60*1000,2*60*1000,LocationRequest.PRIORITY_HIGH_ACCURACY); //5 hours= hours * 60 min*60 sec* 1000 milliseconds
LocationAPIclient.connect();
}
break;
case DetectedActivity.UNKNOWN:
Log.d(TAG, "UnKnown " + activity.getConfidence());
break;
}
}
}
public void setTimer(int Minutes) {
Log.d(TAG, "==================================================");
Log.d(TAG, "Set Timeer Starts It will Run Every " + Minutes);
int MilliSeconds = 60000 * Minutes;
final Handler handler = new Handler();
timer = new Timer();
TimerTask doAsynchronousTask = new TimerTask() {
@Override
public void run() {
handler.post(new Runnable() {
public void run() {
try {
//CODE THAT YOU WANT TO EXECUTE AT GIVEN INTERVAL
} catch (Exception e) {
// TODO Auto-generated catch block
}
}
});
}
};
timer.schedule(doAsynchronousTask, 0, MilliSeconds);
Log.d(TAG, "==================================================");
}
@Override
public void onConnected(@Nullable Bundle bundle) {
Log.d(TAG, "On Connected Running");
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
mCurrentLocation = LocationServices.FusedLocationApi.getLastLocation(LocationAPIclient);
if (mCurrentLocation!=null){
Log.d(TAG,"Last Known Location Is not Null ");
new Location_sendeToServer_AsyncTask(this).execute(String.valueOf(mCurrentLocation.getLatitude()),String.valueOf(mCurrentLocation.getLongitude()),String.valueOf(mCurrentLocation.getAccuracy()));
}
else {
Log.d(TAG,"Last Known Location Is NULL Start Location Updates");
LocationServices.FusedLocationApi.requestLocationUpdates(LocationAPIclient,mLocationRequest,this);
}
}
@Override
public void onConnectionSuspended(int i) {
}
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
}
@Override
public void onLocationChanged(Location location) {
Log.d(TAG,"On Location Changed Calling");
mCurrentLocation=location;
new Location_sendeToServer_AsyncTask(this).execute(String.valueOf(mCurrentLocation.getLatitude()),String.valueOf(mCurrentLocation.getLongitude()),String.valueOf(mCurrentLocation.getAccuracy()));
Log.d(TAG,"Stopping Location Update");
// LocationServices.FusedLocationApi.removeLocationUpdates(LocationAPIclient,this);
}
public void requestLocatonSetting(int Interval,int FastestInterval,int LocationAccuracy){
mLocationRequest=new LocationRequest();
mLocationRequest.setInterval(Interval);
mLocationRequest.setFastestInterval(FastestInterval);
mLocationRequest.setPriority(LocationAccuracy);
}
}
目录包含src
和src/service/api.clj
。 src/user.clj
下的所有文件都在重新加载,但是lein完全忽略了src/service
中的任何更改。
src/user.clj
即使我删除(ns user
(:require [ragtime.jdbc :as jdbc]
[ragtime.repl :as repl]))
...
(defn migrate []
(repl/migrate (load-config)))
定义,REPL也会将其放在migrate
命名空间中,lein会在执行user
后使用lein run -m user/migrate
运行它,并且不会加载lein clean
{1}}也是。
如何将我的更改加载到(load-file "src/user.clj")
?
答案 0 :(得分:0)
Lein只在源路径目录中查找代码。如果您没有指定,则假定src
。在你的project.clj中,这将是建议的条目:
:source-paths ["dev" "src"]
为了能够从REPL重新加载代码,这将适用于user.clj
:
(ns user
(:require [clojure.tools.namespace.repl :refer (refresh refresh-all)]
[clojure.stacktrace]
[clojure.pprint :as pp]))
;;
;; To run open a REPL and:
;; (reset)
;; (core/migrate)
;; Repeat those two commands after every source code change you make
;;
(defn reset []
(refresh))
user.clj
可以放在dev
目录下。
您的问题的答案是我认为user.clj
应该很少更改,以至于在您进行更改后重新启动JVM / REPL不是问题。经常更改的代码应位于src
目录下,不应命名为名称空间user
。您拥有的主入口点代码通常位于名为core.clj
的文件中。因此,您应将user.clj
文件的内容放在core
命名空间中,即放在core.clj
下的src
文件中。