@Override
	public JSONObject addUserActivity(String userId, Long qId, String answer,
			Long time) throws JSONException{
		List<User> result = null;
		boolean hasAttempted = false;
		JSONObject mainojb=new JSONObject();
		try {
			pm = PMF.get().getPersistenceManager();

			Query query = pm.newQuery(User.class, ":p.contains(userId)");
			result = (List<User>) query.execute(userId);
			List<Long> userActivity = result.get(0).getUserActivity();
			pm.close();
			if (userActivity != null) {
				for (int i = 0; i < userActivity.size(); i++) {
					Long activityId = userActivity.get(i);
					Long DBqId = getQuestionIdFromActivityId(activityId);
					if (DBqId.equals(qId)) {
						hasAttempted = true;
						break;

					}
				}

			}
		} catch (Exception e) {
			LOGGER.log(Level.SEVERE, e.getMessage());
		}

		if (!hasAttempted) {
			long aid = addNewActivity(qId, answer, time);
			pm = PMF.get().getPersistenceManager();
			Query query = pm.newQuery(User.class, ":p.contains(userId)");
			result = (List<User>) query.execute(userId);
			if (result != null) {
				boolean isSuccess = result.get(0).addUserActivity(aid);
				pm.close();
				if(isSuccess)
				{
					Question ques=getQuestion(qId);
					if(ques!=null)
					{
						if(ques.getAnswer().equals(answer))
							mainojb.put("Response", "Correct");
						else
							mainojb.put("Response", "Wrong");
					}
					else
						mainojb.put("Response", "Error");
						return mainojb;
				}
			}
			mainojb.put("Response", "Error");
			return mainojb;
		} else {
			mainojb.put("Response", "Attemped");
			return mainojb;
		}
	}