So what you are looking for is $ionicHistory.backView() or $ionicHistory.backTitle(). If you are using angular states and routing and views.
So in a controller you would call:
$scope.lastView = $ionicHistory.backView()
This gives the the last view you were in. So if you go from A to B it will give you A.
If you want the title of the last view call this in a controller:
$scope.lastViewTitle = $ionicHistory.backTitle()
This gives you a string, which is whatever title you gave the previous view. This would return "My Page" if you called backTitle() after you just left this view.
<ion-view view-title="My Page">
<ion-content>
Hello!
</ion-content>
</ion-view>
You can read more here:
http://ionicframework.com/docs/api/service/$ionicHistory/
If you dont want views but states, you should be able to grab the previous state on $stateChangeSuccess that is broadcast.
$rootScope.$on('$stateChangeSuccess', function (ev, to, toParams, from, fromParams) {
//assign the "from" parameter to something
});